Documentation ¶
Overview ¶
Package echox simplifies initializing a new echo service.
Index ¶
- Variables
- func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet, defaultListen string)
- func SkipDefaultEndpoints(c echo.Context) bool
- type CheckFunc
- type Config
- type Option
- type Server
- func (s *Server) AddHandler(h handler) *Server
- func (s *Server) AddReadinessCheck(name string, f CheckFunc) *Server
- func (s *Server) Handler() http.Handler
- func (s *Server) Run() error
- func (s *Server) RunWithContext(ctx context.Context) error
- func (s *Server) Serve(listener net.Listener) error
- func (s *Server) ServeWithContext(ctx context.Context, listener net.Listener) error
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultServerShutdownTimeout sets the default for how long we give the sever // to shutdown before forcefully stopping the server. DefaultServerShutdownTimeout = 5 * time.Second )
var ( // ErrInvalidTrustedProxyIP is returned when an invalid ip is provided as a trusted proxy. ErrInvalidTrustedProxyIP = errors.New("invalid trusted proxy ip") )
Functions ¶
func MustViperFlags ¶
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 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
ConfigFromViper builds a new Config from viper.
func (Config) WithListen ¶ added in v0.0.8
WithListen sets the listen address to serve the echo server on.
func (Config) WithMiddleware ¶ added in v0.0.8
WithMiddleware includes the provided middleware when echo is initialized.
func (Config) WithShutdownGracePeriod ¶ added in v0.0.8
WithShutdownGracePeriod sets the grace period for in flight requests before shutting down.
func (Config) WithTrustedProxies ¶ added in v0.0.8
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 ¶
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 ¶
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) RunWithContext ¶ added in v0.0.6
RunWithContext listens and serves the echo server on the configured address. See ServeWithContext for more details.
func (*Server) Serve ¶
Serve serves an http server on the provided listener. See ServeWithContext for more details.
func (*Server) ServeWithContext ¶ added in v0.0.6
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