Documentation ¶
Index ¶
- Variables
- func BodyDumpOnHeader() echo.MiddlewareFunc
- func DefaultLogger(level zerolog.Level) echo.MiddlewareFunc
- func DefaultRequestZeroLoggerConfig() echo.MiddlewareFunc
- func GetDBX(c echo.Context) (*sqlx.DB, error)
- func GetIDToken(c echo.Context) (*auth.Token, error)
- func GetLogger(c echo.Context) zerolog.Logger
- func LoggedUserIs(c echo.Context, rol string) bool
- func LoggedUserIsAny(c echo.Context, roles []string) bool
- func RequestID(c echo.Context) string
- func SetLogger(c echo.Context, logger zerolog.Logger)
- type AuthClient
- type AuthMiddleware
- type SQLX
- type SQLXConfig
Constants ¶
This section is empty.
Variables ¶
var ( DefaultSQLXConfig = SQLXConfig{ Skipper: em.DefaultSkipper, DB: nil, Driver: "", DataSourceName: "", AutoMigrate: false, MigrationPath: "", } )
var ErrDBXMissing = echo.NewHTTPError(http.StatusInternalServerError, "unable to obtain the dbx in context. Please, initiate the sqlx middleware first")
var ErrNoIDTokenFound = fmt.Errorf("IDToken not found in context key %s", userContextField)
Functions ¶
func BodyDumpOnHeader ¶
func BodyDumpOnHeader() echo.MiddlewareFunc
func DefaultLogger ¶
Logger will inject in context a default zerolog logger with all available contextual info. Default logger is a pretty logger with info level and timestamp functionality.
func DefaultRequestZeroLoggerConfig ¶
func DefaultRequestZeroLoggerConfig() echo.MiddlewareFunc
func GetIDToken ¶ added in v0.0.10
GetIDToken extract the token from the context field in userContextField and return it. If no token is found, it returns a ErrNoIDTokenFound.
func LoggedUserIs ¶ added in v0.0.12
LoggedUserIs returns true if a idToken exists in the context and it have the desired rol.
func LoggedUserIsAny ¶ added in v0.0.12
LoggedUserIsAny returns true if a idToken exists in the context and it have, at least, one of the expecified roles.
Types ¶
type AuthClient ¶ added in v0.0.12
type AuthMiddleware ¶ added in v0.0.10
type AuthMiddleware struct {
// contains filtered or unexported fields
}
func DefaultAuthMiddleware ¶ added in v0.0.12
func DefaultAuthMiddleware() *AuthMiddleware
DefaultAuthMiddleware returns the auth middleware with a firebase auth client initialized from env vars.
func NewAuthMiddleware ¶ added in v0.0.10
func NewAuthMiddleware(ctx context.Context, authClient AuthClient) *AuthMiddleware
NewAuthMiddleware return a new auth middleware with the desired authClient attached.
func (*AuthMiddleware) AllowAnonymous ¶ added in v0.0.10
func (a *AuthMiddleware) AllowAnonymous() echo.MiddlewareFunc
AllowAnonymous will let pass all petitions trying to find a JWT in headers and loging in the user if the JWT is found.
func (*AuthMiddleware) LoggedUser ¶ added in v0.0.10
func (a *AuthMiddleware) LoggedUser() echo.MiddlewareFunc
LoggedUsers searchs for a valid JWT and logs in the founded user. If no JWT is found, it returns a 401 unauthorized standar error, stopping the request.
func (*AuthMiddleware) WithAny ¶ added in v0.0.12
func (a *AuthMiddleware) WithAny(roles []string) echo.MiddlewareFunc
WhitAny searchs for a valid JWT with at least one of the desired roles as a boolean true key in the token Claims and logs in the founded user. If no JWT with one desired rol is found, it returns a 401 or 403 standard error, stopping the request.
func (*AuthMiddleware) WithRol ¶ added in v0.0.10
func (a *AuthMiddleware) WithRol(rol string) echo.MiddlewareFunc
WithRol searchs for a valid JWT with the desired rol as a boolean true key in the token Claims and logs in the founded user. If no JWT with the rol is found, it returns a 401 or 403 standard error, stopping the request.
type SQLX ¶ added in v0.0.14
type SQLX struct {
// contains filtered or unexported fields
}
func (*SQLX) WithConfig ¶ added in v0.0.16
func (m *SQLX) WithConfig(config SQLXConfig) echo.MiddlewareFunc
type SQLXConfig ¶ added in v0.0.14
type SQLXConfig struct { // Skipper defines a function to skip middleware. Skipper em.Skipper // BeforeFunc defines a function which is executed just before the middleware. BeforeFunc em.BeforeFunc // DB is the inner db to be used. If is not provided, a new db will be open based either // in the Driver and DataSourceName attribute or in the default env vars. DB *sql.DB // Driver defines the driver to be used when a new database is tried to be opened. // If DB is provided, the middleware will never tried to stablish this connection. Driver string // DataSorceName is used in conjuntion with the Driver attribute when a new database is tried to be opened. // If DB is provided, the middleware will never tried to stablish this connection. DataSourceName string // AutoMigrate defines if migrations will apply on middleware initialization. If true, // you must provide a MigrationPath folder with the migrations files. // pressly/goose (https://github.com/pressly/goose) is used to execute the migrations. // The default SQLX middleware set this attribute to true AutoMigrate bool // MigrationPath defines the path to migrations files. Is used on middleware initialization // If AutoMigrate is set to true. Also used in calls to SQLXApplyMigrations. // pressly/goose (https://github.com/pressly/goose) is used to execute the migrations. // The default SQLX middleware set this attribute to ./migration MigrationPath string }