echokit

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const CONTEXT_KEY_SESSION_STORE = "fx-session-store"

Variables

This section is empty.

Functions

func DeleteSession

func DeleteSession(name string, c echo.Context) error

func ErrorHandler added in v0.9.0

func ErrorHandler(e *echo.Echo) echo.HTTPErrorHandler

ErrorHandler returns a custom HTTP error handler that wraps non-HTTPError errors in HTTPError with status 500 and includes request ID in the response message, then delegates to Echo's default error handler to send the response.

func GetSession

func GetSession(name string, c echo.Context) (*sessions.Session, error)

func NewAuthenticationMiddleware

func NewAuthenticationMiddleware(authenticator Authenticator, options ...AuthenticationMiddlewareOption) echo.MiddlewareFunc

func NewEchoSlogLogger

func NewEchoSlogLogger(
	logger *slog.Logger,
	level *slog.LevelVar) echo.Logger

func NewSessionMiddleware

func NewSessionMiddleware(sessionStore sessions.Store) echo.MiddlewareFunc

func NewTestDeleteRequest added in v0.10.0

func NewTestDeleteRequest(e *echo.Echo, path string) (echo.Context, *httptest.ResponseRecorder)

NewTestDeleteRequest creates a test DELETE request

func NewTestGetRequest added in v0.10.0

func NewTestGetRequest(e *echo.Echo, path string) (echo.Context, *httptest.ResponseRecorder)

NewTestGetRequest creates a test GET request with the given path

func NewTestPatchJSONRequest added in v0.10.0

func NewTestPatchJSONRequest(e *echo.Echo, path string, body string) (echo.Context, *httptest.ResponseRecorder)

NewTestPatchJSONRequest creates a test PATCH request with JSON body

func NewTestPostJSONRequest added in v0.10.0

func NewTestPostJSONRequest(e *echo.Echo, path string, body string) (echo.Context, *httptest.ResponseRecorder)

NewTestPostJSONRequest creates a test POST request with JSON body

func NewTestPutJSONRequest added in v0.10.0

func NewTestPutJSONRequest(e *echo.Echo, path string, body string) (echo.Context, *httptest.ResponseRecorder)

NewTestPutJSONRequest creates a test PUT request with JSON body

func PanicLogger added in v0.9.0

func PanicLogger(c echo.Context, err error, stack []byte) error

PanicLogger logs panics at ERROR level with error message, stack trace, URI, and method. This function is meant to be used as the LogErrorFunc in echomiddleware.RecoverConfig.

func RequestLogger added in v0.9.0

func RequestLogger() echo.MiddlewareFunc

RequestLogger returns a middleware that logs all HTTP requests with structured logging. All requests are logged at INFO level by default.

func RequestLoggerWithConfig added in v0.9.0

func RequestLoggerWithConfig(config RequestLoggerConfig) echo.MiddlewareFunc

RequestLoggerWithConfig returns a middleware that logs all HTTP requests with structured logging. Paths specified in config.DebugPaths are logged at DEBUG level, all others at INFO level.

func RequireAuthenticated added in v0.10.0

func RequireAuthenticated() echo.MiddlewareFunc

func RequirePermission added in v0.10.0

func RequirePermission(permission string, orPermission ...string) echo.MiddlewareFunc

func RequirePermissions added in v0.10.0

func RequirePermissions(permissions []string, orPermissions ...[]string) echo.MiddlewareFunc

func WithAuthenticatedUserCallback

func WithAuthenticatedUserCallback(callback func(AuthenticatedUser) error) func(*AuthenticationMiddlewareOptions)

Types

type Auth0Authenticator

type Auth0Authenticator struct {
	// contains filtered or unexported fields
}

func (*Auth0Authenticator) AuthenticateRequest added in v0.10.0

func (a *Auth0Authenticator) AuthenticateRequest(c echo.Context) error

func (*Auth0Authenticator) GetAuthCodeURL

func (a *Auth0Authenticator) GetAuthCodeURL(c echo.Context) (*url.URL, error)

func (*Auth0Authenticator) GetAuthenticatedUser

func (a *Auth0Authenticator) GetAuthenticatedUser(c echo.Context) (*AuthenticatedUser, error)

func (*Auth0Authenticator) HandleAuthenticationCallback

func (a *Auth0Authenticator) HandleAuthenticationCallback(c echo.Context) (bool, error)

func (*Auth0Authenticator) HandleNotAuthenticated

func (a *Auth0Authenticator) HandleNotAuthenticated(c echo.Context) error

func (*Auth0Authenticator) IsAuthenticated

func (a *Auth0Authenticator) IsAuthenticated(c echo.Context) (bool, error)

func (*Auth0Authenticator) Login

func (a *Auth0Authenticator) Login(c echo.Context) error

func (*Auth0Authenticator) Logout

func (a *Auth0Authenticator) Logout(c echo.Context) error

type Auth0AuthenticatorOption

type Auth0AuthenticatorOption func(*Auth0Authenticator)

type Auth0Config

type Auth0Config struct {
	Audience     string
	CallbackPath string
	ClientId     string
	ClientSecret string
	Domain       string
}

type Auth0CustomClaims added in v0.9.0

type Auth0CustomClaims struct {
	Name              string   `json:"name"`
	GivenName         string   `json:"given_name"`
	FamilyName        string   `json:"family_name"`
	MiddleName        string   `json:"middle_name"`
	Nickname          string   `json:"nickname"`
	PreferredUsername string   `json:"preferred_username"`
	Email             string   `json:"email"`
	EmailVerified     bool     `json:"email_verified"`
	Picture           string   `json:"picture"`
	UpdatedAt         int64    `json:"updated_at"`
	Permissions       []string `json:"permissions"`
}

func (Auth0CustomClaims) Validate added in v0.9.0

func (c Auth0CustomClaims) Validate(ctx context.Context) error

type Auth0JWTAuthenticator added in v0.9.0

type Auth0JWTAuthenticator struct {
	// contains filtered or unexported fields
}

func (*Auth0JWTAuthenticator) AuthenticateRequest added in v0.10.0

func (a *Auth0JWTAuthenticator) AuthenticateRequest(c echo.Context) error

func (*Auth0JWTAuthenticator) GetAuthenticatedUser added in v0.9.0

func (a *Auth0JWTAuthenticator) GetAuthenticatedUser(c echo.Context) (*AuthenticatedUser, error)

func (*Auth0JWTAuthenticator) HandleNotAuthenticated added in v0.9.0

func (a *Auth0JWTAuthenticator) HandleNotAuthenticated(c echo.Context) error

func (*Auth0JWTAuthenticator) IsAuthenticated added in v0.9.0

func (a *Auth0JWTAuthenticator) IsAuthenticated(c echo.Context) (bool, error)

type Auth0JWTAuthenticatorOption added in v0.9.0

type Auth0JWTAuthenticatorOption func(*Auth0JWTAuthenticator)

type AuthenticatedUser

type AuthenticatedUser struct {
	Sub               string
	Name              string
	GivenName         string
	FamilyName        string
	MiddleName        string
	Nickname          string
	PreferredUsername string
	Email             string
	EmailVerified     bool
	Picture           string
	UpdatedAt         int64
	Permissions       []string
}

type AuthenticationMiddlewareOption added in v0.10.0

type AuthenticationMiddlewareOption func(*AuthenticationMiddlewareOptions)

type AuthenticationMiddlewareOptions added in v0.10.0

type AuthenticationMiddlewareOptions struct {
	AuthenticatedUserCallback func(AuthenticatedUser) error
}

type Authenticator

type Authenticator interface {
	AuthenticateRequest(c echo.Context) error
	GetAuthenticatedUser(c echo.Context) (*AuthenticatedUser, error)
	IsAuthenticated(c echo.Context) (bool, error)
	HandleNotAuthenticated(c echo.Context) error
}

func GetAuthenticator

func GetAuthenticator(c echo.Context) (Authenticator, error)

func NewAuth0Authenticator

func NewAuth0Authenticator(config Auth0Config) (Authenticator, error)

func NewAuth0JWTAuthenticator added in v0.9.0

func NewAuth0JWTAuthenticator(config Auth0Config) (Authenticator, error)

func NewEntraIDJWTAuthenticator added in v0.9.0

func NewEntraIDJWTAuthenticator(tenantID, audience string) (Authenticator, error)

NewEntraIDJWTAuthenticator creates a JWT authenticator for Microsoft Entra ID

type CustomValidator added in v0.9.0

type CustomValidator struct {
	// contains filtered or unexported fields
}

CustomValidator wraps the validator for Echo

func NewValidator added in v0.9.0

func NewValidator() *CustomValidator

NewValidator creates a new validator instance

func (*CustomValidator) Validate added in v0.9.0

func (cv *CustomValidator) Validate(i interface{}) error

Validate implements Echo's Validator interface

type EchoSlogLogger

type EchoSlogLogger struct {
	// contains filtered or unexported fields
}

func (EchoSlogLogger) Debug

func (l EchoSlogLogger) Debug(i ...interface{})

func (EchoSlogLogger) Debugf

func (l EchoSlogLogger) Debugf(format string, args ...interface{})

func (EchoSlogLogger) Debugj

func (l EchoSlogLogger) Debugj(j echolog.JSON)

func (EchoSlogLogger) Error

func (l EchoSlogLogger) Error(i ...interface{})

func (EchoSlogLogger) Errorf

func (l EchoSlogLogger) Errorf(format string, args ...interface{})

func (EchoSlogLogger) Errorj

func (l EchoSlogLogger) Errorj(j echolog.JSON)

func (EchoSlogLogger) Fatal

func (l EchoSlogLogger) Fatal(i ...interface{})

func (EchoSlogLogger) Fatalf

func (l EchoSlogLogger) Fatalf(format string, args ...interface{})

func (EchoSlogLogger) Fatalj

func (l EchoSlogLogger) Fatalj(j echolog.JSON)

func (EchoSlogLogger) Info

func (l EchoSlogLogger) Info(i ...interface{})

func (EchoSlogLogger) Infof

func (l EchoSlogLogger) Infof(format string, args ...interface{})

func (EchoSlogLogger) Infoj

func (l EchoSlogLogger) Infoj(j echolog.JSON)

func (*EchoSlogLogger) Level

func (l *EchoSlogLogger) Level() echolog.Lvl

func (*EchoSlogLogger) Output

func (l *EchoSlogLogger) Output() io.Writer

func (EchoSlogLogger) Panic

func (l EchoSlogLogger) Panic(i ...interface{})

func (EchoSlogLogger) Panicf

func (l EchoSlogLogger) Panicf(format string, args ...interface{})

func (EchoSlogLogger) Panicj

func (l EchoSlogLogger) Panicj(j echolog.JSON)

func (*EchoSlogLogger) Prefix

func (l *EchoSlogLogger) Prefix() string

func (*EchoSlogLogger) Print

func (l *EchoSlogLogger) Print(i ...interface{})

func (*EchoSlogLogger) Printf

func (l *EchoSlogLogger) Printf(format string, args ...interface{})

func (EchoSlogLogger) Printj

func (l EchoSlogLogger) Printj(j echolog.JSON)

func (*EchoSlogLogger) SetHeader

func (l *EchoSlogLogger) SetHeader(h string)

func (*EchoSlogLogger) SetLevel

func (l *EchoSlogLogger) SetLevel(v echolog.Lvl)

func (*EchoSlogLogger) SetOutput

func (l *EchoSlogLogger) SetOutput(w io.Writer)

func (*EchoSlogLogger) SetPrefix

func (l *EchoSlogLogger) SetPrefix(p string)

func (EchoSlogLogger) Warn

func (l EchoSlogLogger) Warn(i ...interface{})

func (EchoSlogLogger) Warnf

func (l EchoSlogLogger) Warnf(format string, args ...interface{})

func (EchoSlogLogger) Warnj

func (l EchoSlogLogger) Warnj(j echolog.JSON)

type EntraIDCustomClaims added in v0.9.0

type EntraIDCustomClaims struct {
	Name              string `json:"name"`
	GivenName         string `json:"given_name"`
	FamilyName        string `json:"family_name"`
	MiddleName        string `json:"middle_name"`
	PreferredUsername string `json:"preferred_username"`
	Email             string `json:"email"`
	Picture           string `json:"picture"`
	UpdatedAt         int64  `json:"updated_at"`
	Scp               string `json:"scp"`
}

func (EntraIDCustomClaims) Validate added in v0.9.0

func (c EntraIDCustomClaims) Validate(ctx context.Context) error

type EntraIDJWTAuthenticator added in v0.9.0

type EntraIDJWTAuthenticator struct {
	// contains filtered or unexported fields
}

func (*EntraIDJWTAuthenticator) AuthenticateRequest added in v0.10.0

func (a *EntraIDJWTAuthenticator) AuthenticateRequest(c echo.Context) error

func (*EntraIDJWTAuthenticator) GetAuthenticatedUser added in v0.9.0

func (a *EntraIDJWTAuthenticator) GetAuthenticatedUser(c echo.Context) (*AuthenticatedUser, error)

func (*EntraIDJWTAuthenticator) HandleNotAuthenticated added in v0.9.0

func (a *EntraIDJWTAuthenticator) HandleNotAuthenticated(c echo.Context) error

func (*EntraIDJWTAuthenticator) IsAuthenticated added in v0.9.0

func (a *EntraIDJWTAuthenticator) IsAuthenticated(c echo.Context) (bool, error)

type FakeAuthenticator added in v0.10.0

type FakeAuthenticator struct {
	AuthenticateRequestFake    func(c echo.Context) error
	GetAuthenticatedUserFake   func(c echo.Context) (*AuthenticatedUser, error)
	IsAuthenticatedFake        func(c echo.Context) (bool, error)
	HandleNotAuthenticatedFake func(c echo.Context) error
}

func (*FakeAuthenticator) AuthenticateRequest added in v0.10.0

func (f *FakeAuthenticator) AuthenticateRequest(c echo.Context) error

func (*FakeAuthenticator) GetAuthenticatedUser added in v0.10.0

func (f *FakeAuthenticator) GetAuthenticatedUser(c echo.Context) (*AuthenticatedUser, error)

func (*FakeAuthenticator) HandleNotAuthenticated added in v0.10.0

func (f *FakeAuthenticator) HandleNotAuthenticated(c echo.Context) error

func (*FakeAuthenticator) IsAuthenticated added in v0.10.0

func (f *FakeAuthenticator) IsAuthenticated(c echo.Context) (bool, error)

type LayoutModelFunc

type LayoutModelFunc func(c echo.Context, path string, tmpl *template.Template, data interface{}) (interface{}, error)

type LogWriter

type LogWriter struct {
	// contains filtered or unexported fields
}

func (*LogWriter) Write

func (lw *LogWriter) Write(p []byte) (n int, err error)

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(templateFilesPath string, layoutModelFunc LayoutModelFunc) *Renderer

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, path string, data interface{}, c echo.Context) error

type RequestLoggerConfig added in v0.9.0

type RequestLoggerConfig struct {
	// DebugPaths is a list of paths that should be logged at DEBUG level instead of INFO.
	// All other paths will be logged at INFO level.
	DebugPaths []string
}

RequestLoggerConfig defines the configuration for the request logger middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL