echox

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 20 Imported by: 8

Documentation

Overview

Package echox simplifies initializing a new echo service.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultServerShutdownTimeout sets the default for how long we give the sever
	// to shutdown before forcefully stopping the server.
	DefaultServerShutdownTimeout = 5 * time.Second
)
View Source
var (
	// ErrInvalidTrustedProxyIP is returned when an invalid ip is provided as a trusted proxy.
	ErrInvalidTrustedProxyIP = errors.New("invalid trusted proxy ip")
)

Functions

func MustViperFlags

func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet, defaultListen string)

MustViperFlags returns the cobra flags and wires them up with viper to prevent code duplication

func SkipDefaultEndpoints added in v0.0.7

func SkipDefaultEndpoints(c echo.Context) bool

SkipDefaultEndpoints returns true when the provided context request is for /version /livez /readyz or /metrics

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

CheckFunc is a function that can be used to check the status of a service.

type Config

type Config struct {
	// Debug enables echo's Debug option.
	Debug bool

	// Listen sets the listen address to serve the echo server on.
	Listen string

	// ShutdownGracePeriod sets the grace period for in flight requests before shutting down.
	ShutdownGracePeriod time.Duration

	// TrustedProxies defines the allowed ip / network ranges to trust a proxy from.
	TrustedProxies []string

	// Middleware includes the provided middleware when echo is initialized.
	Middleware []echo.MiddlewareFunc
}

Config is used to configure a new ginx server

func ConfigFromViper added in v0.0.7

func ConfigFromViper(v *viper.Viper) Config

ConfigFromViper builds a new Config from viper.

func (Config) WithDebug added in v0.0.8

func (c Config) WithDebug(debug bool) Config

WithDebug enables echo's Debug option.

func (Config) WithListen added in v0.0.8

func (c Config) WithListen(listen string) Config

WithListen sets the listen address to serve the echo server on.

func (Config) WithMiddleware added in v0.0.8

func (c Config) WithMiddleware(mdw ...echo.MiddlewareFunc) Config

WithMiddleware includes the provided middleware when echo is initialized.

func (Config) WithShutdownGracePeriod added in v0.0.8

func (c Config) WithShutdownGracePeriod(period time.Duration) Config

WithShutdownGracePeriod sets the grace period for in flight requests before shutting down.

func (Config) WithTrustedProxies added in v0.0.8

func (c Config) WithTrustedProxies(trust ...string) Config

WithTrustedProxies defines the allowed ip / network ranges to trust a proxy from.

type Option added in v0.3.7

type Option func(c *Server)

Option sets the server function definition

func WithLoggingSkipper added in v0.3.7

func WithLoggingSkipper(skipper middleware.Skipper) Option

WithLoggingSkipper sets the echozap middleware Skipper config option

type Server

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

Server implements the HTTP Server

func NewServer

func NewServer(logger *zap.Logger, cfg Config, version *versionx.Details, options ...Option) (*Server, error)

NewServer will return an opinionated echo server for processing API requests.

func (*Server) AddHandler

func (s *Server) AddHandler(h handler) *Server

AddHandler provides the ability to add additional HTTP handlers that process requests. The handler that is provided should have a Routes(*echo.Group) function, which allows the routes to be added to the server.

func (*Server) AddReadinessCheck

func (s *Server) AddReadinessCheck(name string, f CheckFunc) *Server

AddReadinessCheck will accept a function to be ran during calls to /readyx. These functions should accept a context and only return an error. When adding a readiness check a name is also provided, this name will be used when returning the state of all the checks

func (*Server) Handler added in v0.0.6

func (s *Server) Handler() http.Handler

Handler returns a new http.Handler for serving requests.

func (*Server) Run

func (s *Server) Run() error

Run listens and serves the echo server on the configured address.

func (*Server) RunWithContext added in v0.0.6

func (s *Server) RunWithContext(ctx context.Context) error

RunWithContext listens and serves the echo server on the configured address. See ServeWithContext for more details.

func (*Server) Serve

func (s *Server) Serve(listener net.Listener) error

Serve serves an http server on the provided listener. See ServeWithContext for more details.

func (*Server) ServeWithContext added in v0.0.6

func (s *Server) ServeWithContext(ctx context.Context, listener net.Listener) error

ServeWithContext serves an http server on the provided listener. Serve blocks until SIGINT or SIGTERM are signalled, or if the http serve fails. A graceful shutdown will be attempted

Directories

Path Synopsis
Package echozap implements an echo.Logger interface as well as an echo Middleware to log requests.
Package echozap implements an echo.Logger interface as well as an echo Middleware to log requests.

Jump to

Keyboard shortcuts

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