echokit

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package echokit provides helper for echo web framework app

Index

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 PrintRoutes

func PrintRoutes(e *echo.Echo)

PrintRoutes prints *echo.Echo routes.

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

func Validate(ctx echo.Context, req interface{}) *web.HTTPError

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

type HealthCheckFunc func(ctx context.Context) error

HealthCheckFunc is healthcheck interface func.

type Option

type Option func(*options)

Option sets options for request middleware.

func WithRequestIDKey

func WithRequestIDKey(key string) Option

WithRequestIDKey returns an Option which sets `key` as request-ID lookup to use for logging server requests.

func WithTraceIDKey

func WithTraceIDKey(key string) Option

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

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

Jump to

Keyboard shortcuts

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