Documentation ¶
Overview ¶
Package echokit provides helper for echo web framework app
Index ¶
- func BodyDumpHandler(skipper middleware.Skipper) echo.MiddlewareFunc
- func PrintRoutes(e *echo.Echo)
- func RequestIDLoggerMiddleware(cfg *RuntimeConfig, o ...Option) echo.MiddlewareFunc
- func RunServer(e *echo.Echo, cfg *RuntimeConfig)
- func RunServerWithContext(appCtx context.Context, e *echo.Echo, cfg *RuntimeConfig)
- func TimeoutMiddleware(cfg *TimeoutConfig) echo.MiddlewareFunc
- func Validate(ctx echo.Context, req interface{}) *web.HTTPError
- func ValidatorTranslatorMiddleware(v *validator.Validate) echo.MiddlewareFunc
- type HealthCheckFunc
- type Option
- type RuntimeConfig
- type TimeoutConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BodyDumpHandler ¶
func BodyDumpHandler(skipper middleware.Skipper) echo.MiddlewareFunc
BodyDumpHandler logs incoming request & outgoing response body.
func RequestIDLoggerMiddleware ¶
func RequestIDLoggerMiddleware(cfg *RuntimeConfig, o ...Option) echo.MiddlewareFunc
RequestIDLoggerMiddleware - adds request ID for incoming http request. it also set request with new context with logger it's useful when you want to using log package with requestID.
func RunServer ¶
func RunServer(e *echo.Echo, cfg *RuntimeConfig)
RunServer run graceful restapi server.
func RunServerWithContext ¶
func RunServerWithContext(appCtx context.Context, e *echo.Echo, cfg *RuntimeConfig)
RunServerWithContext run graceful restapi server with existing background context provides default '/actuator/health' as healthcheck endpoint provides '/metrics' as prometheus metrics endpoint. set echo.Validator using `web.Validator` from `web` package.
func TimeoutMiddleware ¶
func TimeoutMiddleware(cfg *TimeoutConfig) echo.MiddlewareFunc
TimeoutMiddleware sets upstream request context's timeout.
func Validate ¶
Validate validates request body for incoming echo.Context request returns web.HTTPError contains field errors (if any).
func ValidatorTranslatorMiddleware ¶
func ValidatorTranslatorMiddleware(v *validator.Validate) echo.MiddlewareFunc
ValidatorTranslatorMiddleware adds request body validator's translator based on 'Accept-Lang' header. currently only suuports ID & EN locale.
Types ¶
type HealthCheckFunc ¶
HealthCheckFunc is healthcheck interface func.
type Option ¶
type Option func(*options)
Option sets options for request middleware.
func WithRequestIDKey ¶
WithRequestIDKey returns an Option which sets `key` as request-ID lookup to use for logging server requests.
func WithTraceIDKey ¶
WithTraceIDKey returns an Option which sets `key` as trace-ID lookup to use for logging server requests.
type RuntimeConfig ¶
type RuntimeConfig struct { Port int `json:"port,omitempty"` Name string `json:"name,omitempty"` BuildInfo string `json:"build_info,omitempty"` ShutdownWaitDuration time.Duration `json:"shutdown_wait_duration,omitempty"` ShutdownTimeoutDuration time.Duration `json:"shutdown_timeout_duration,omitempty"` RequestTimeoutConfig *TimeoutConfig `json:"request_timeout_config,omitempty"` HealthCheckPath string `json:"health_check_path,omitempty"` InfoCheckPath string `json:"info_check_path,omitempty"` HealthCheckFunc `json:"-"` }
RuntimeConfig defines echo REST API runtime config with healthcheck.
func NewRuntimeConfig ¶
func NewRuntimeConfig(cfg config.KVStore, path string) *RuntimeConfig
NewRuntimeConfig returns *RuntimeConfig based on viper configuration with layout:
given config file contents: restapi: port: 8088 request-timeout: 10s healthcheck-path: /health/info info-path: /actuator/info shutdown: wait-duration: 3s timeout-duration: 5s call using `echokit.NewRuntimeConfig(v, "restapi")`.
type TimeoutConfig ¶
type TimeoutConfig struct { Timeout time.Duration `json:"timeout,omitempty"` Skipper middleware.Skipper `json:"-"` }
TimeoutConfig request timeout configuration default value:
- timeout: 7 seconds
- middleware.DefaultSkipper / apply to all url
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package echoapmkit for echo & APM functionalies
|
Package echoapmkit for echo & APM functionalies |
Package echotestkit provides echo test helpers
|
Package echotestkit provides echo test helpers |