Documentation
¶
Index ¶
- Variables
- func CustomHTTPErrorHandler(err error, c echo.Context)
- func GenerateJwtToken(userID any, app string) (string, error)
- func HTTPLogger() echo.MiddlewareFunc
- func IDFromContext(c echo.Context) int64
- func NewActionError(msg string, e error) *echo.HTTPError
- func NewServer(config *Config, logger *zap.Logger, registerRoutes func(e *echo.Echo))
- func ParseUserIDFromToken(c echo.Context) (any, error)
- func RequestFailureDumper(c echo.Context, reqBody, resBody []byte)
- func Response(c echo.Context, rb interface{}, e error) error
- func Restricted() echo.MiddlewareFunc
- func Shutdown(err error)
- func Start() error
- type Config
- type CustomBinder
- type JwtCustomClaims
- type ResponseBody
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CustomHTTPErrorHandler ¶
func GenerateJwtToken ¶
GenerateJwtToken creates a JWT token for any type of userID (int, string, etc).
func HTTPLogger ¶
func HTTPLogger() echo.MiddlewareFunc
HTTPLogger returns a middleware that logs HTTP requests.
func IDFromContext ¶
IDFromContext extracts an integer ID from the Echo context params.
func ParseUserIDFromToken ¶
ParseUserIDFromToken extracts the user_id from JWT claims.
func RequestFailureDumper ¶
RequestFailureDumper logs failed HTTP requests and their payloads for easier debugging. It is triggered only when the response status is not 200 OK.
func Restricted ¶
func Restricted() echo.MiddlewareFunc
Restricted returns JWT middleware for Echo framework.
Types ¶
type Config ¶
type Config struct {
ServiceName string
ServiceVersion string
Address string
IsDev bool
AppName string
JwtSecret string
}
Config holds configuration settings for the REST server.
type CustomBinder ¶
type CustomBinder struct {
// contains filtered or unexported fields
}
func (*CustomBinder) Validate ¶
func (cb *CustomBinder) Validate(obj interface{}) (resp *validate.Response)
Validate the request when binding
type JwtCustomClaims ¶
type JwtCustomClaims struct {
UserID any `json:"user_id"`
App string `json:"app"`
jwt.RegisteredClaims
}
JwtCustomClaims defines the JWT payload structure.
type ResponseBody ¶
type ResponseBody struct {
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
Total int64 `json:"total,omitempty"`
}
func NewResponseBody ¶
func NewResponseBody() *ResponseBody
func (*ResponseBody) Body ¶
func (r *ResponseBody) Body(data interface{}, total int64)
Click to show internal directories.
Click to hide internal directories.