Documentation
¶
Overview ¶
Package echox adds helper functions for the echo server
Index ¶
- Variables
- func EchoContextFromContext(ctx context.Context) (*echo.Context, error)
- func EchoContextToContextMiddleware() echo.MiddlewareFunc
- func GetActorSubject(c echo.Context) (string, error)
- func NewTestContextWithValidUser(subject string) (*echo.Context, error)
- type Config
- func (c Config) WithAutoCert(host string) Config
- func (c Config) WithDebug(debug bool) Config
- func (c Config) WithDefaultReadTimeout(period time.Duration) Config
- func (c Config) WithDefaultTLSConfig() Config
- func (c Config) WithDefaults() Config
- func (c Config) WithDev(dev bool) Config
- func (c Config) WithHTTPS(https bool) Config
- func (c Config) WithIdleTimeout(period time.Duration) Config
- func (c Config) WithListen(listen string) Config
- func (c Config) WithMiddleware(mdw ...echo.MiddlewareFunc) Config
- func (c Config) WithReadHeaderTimeout(period time.Duration) Config
- func (c Config) WithShutdownGracePeriod(period time.Duration) Config
- func (c Config) WithTLSCerts(certFile, certKey string) Config
- func (c Config) WithTLSDefaults() Config
- func (c Config) WithWriteTimeout(period time.Duration) Config
- type ContextKey
- type CustomContext
- type HTTPSConfig
- type Server
- func (s *Server) AddHandler(h handler) *Server
- func (s *Server) Handler() http.Handler
- func (s *Server) RunWithContext(ctx context.Context) error
- func (s *Server) ServeHTTPSWithContext(ctx context.Context, listener net.Listener) error
- func (s *Server) ServeHTTPWithContext(ctx context.Context, listener net.Listener) error
- type TLSConfig
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultShutdownGracePeriod sets the default for how long we give the sever // to shutdown before forcefully stopping the server. DefaultShutdownGracePeriod = 5 * time.Second // DefaultReadTimeout sets the default maximum duration for reading the entire request including the body. DefaultReadTimeout = 15 * time.Second // DefaultWriteTimeout sets the default maximum duration before timing out writes of the response. DefaultWriteTimeout = 15 * time.Second // DefaultIdleTimeout sets the default maximum amount of time to wait for the next request when keep-alives are enabled. DefaultIdleTimeout = 30 * time.Second // DefaultReadHeaderTimeout sets the default amount of time allowed to read request headers. DefaultReadHeaderTimeout = 2 * time.Second // DefaultCertFile is the default cert file location DefaultCertFile = "server.crt" // DefaultKeyFile is the default key file location DefaultKeyFile = "server.key" // DefaultTLSConfig is the default TLS config used when HTTPS is enabled DefaultTLSConfig = &tls.Config{ MinVersion: tls.VersionTLS12, CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, PreferServerCipherSuites: true, CipherSuites: []uint16{ tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, }, } )
var ( // ErrJWTMissingInvalid is returned when the JWT is missing or invalid ErrJWTMissingInvalid = errors.New("JWT token missing or invalid") // ErrJWTClaimsInvalid is returned when the token could not be cast to jwt.MapClaims ErrJWTClaimsInvalid = errors.New("JWT claims missing or invalid") // ErrSubjectNotFound is returned when the sub is not found in the JWT claims ErrSubjectNotFound = errors.New("JWT claims missing subject") // ErrUnableToRetrieveEchoContext is returned when the echo context is unable to be parsed from parent context ErrUnableToRetrieveEchoContext = errors.New("unable to retrieve echo context") )
var EchoContextKey = &ContextKey{"EchoContextKey"}
EchoContextKey is the context key for the echo.Context
Functions ¶
func EchoContextFromContext ¶
EchoContextFromContext gets the echo.Context from the parent context
func EchoContextToContextMiddleware ¶
func EchoContextToContextMiddleware() echo.MiddlewareFunc
EchoContextToContextMiddleware is the middleware that adds the echo.Context to the parent context
func GetActorSubject ¶
GetActorSubject returns the user from the echo.Context
Types ¶
type Config ¶
type Config struct {
// Debug enables echo's Debug option.
Debug bool
// Dev enables echo's dev mode options.
Dev bool
// Listen sets the listen address to serve the echo server on.
Listen string
// HTTPS configures an https server
HTTPS bool
// ShutdownGracePeriod sets the grace period for in flight requests before shutting down.
ShutdownGracePeriod time.Duration
// ReadTimeout sets the maximum duration for reading the entire request including the body.
ReadTimeout time.Duration
// WriteTimeout sets the maximum duration before timing out writes of the response.
WriteTimeout time.Duration
// IdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled.
IdleTimeout time.Duration
// ReadHeaderTimeout sets the amount of time allowed to read request headers.
ReadHeaderTimeout 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
// TLSConfig contains the settings for running an HTTPS server.
TLSConfig TLSConfig
}
Config is used to configure a new echo server
func (Config) WithAutoCert ¶
WithAutoCert generates a letsencrypt certificate, a valid host must be provided
func (Config) WithDefaultReadTimeout ¶
WithDefaultReadTimeout sets the maximum duration for reading the entire request including the body.
func (Config) WithDefaultTLSConfig ¶
WithDefaultTLSConfig sets the default TLS Configuration
func (Config) WithDefaults ¶
WithDefaults creates a new config with defaults set if not already defined.
func (Config) WithIdleTimeout ¶
WithIdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled.
func (Config) WithListen ¶
WithListen sets the listen address to serve the echo server on.
func (Config) WithMiddleware ¶
func (c Config) WithMiddleware(mdw ...echo.MiddlewareFunc) Config
WithMiddleware includes the provided middleware when echo is initialized.
func (Config) WithReadHeaderTimeout ¶
WithReadHeaderTimeout sets the amount of time allowed to read request headers.
func (Config) WithShutdownGracePeriod ¶
WithShutdownGracePeriod sets the grace period for in flight requests before shutting down.
func (Config) WithTLSCerts ¶
WithTLSCerts sets the TLS Cert and Key locations
func (Config) WithTLSDefaults ¶
WithTLSDefaults sets tls default settings assuming a default cert and key file location.
type ContextKey ¶
type ContextKey struct {
// contains filtered or unexported fields
}
ContextKey is the key name for the additional context
type CustomContext ¶
CustomContext contains the echo.Context and request context.Context
type HTTPSConfig ¶
type HTTPSConfig struct {
// contains filtered or unexported fields
}
HTTPSConfig contains HTTPS server settings
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements the HTTPS Server
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) RunWithContext ¶
RunWithContext listens and serves the echo server on the configured address. See ServeWithContext for more details.
func (*Server) ServeHTTPSWithContext ¶
ServeHTTPSWithContext serves an https 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
func (*Server) ServeHTTPWithContext ¶
ServeHTTPWithContext 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
type TLSConfig ¶
type TLSConfig struct {
// TLSConfig contains the tls settings
TLSConfig *tls.Config
// AutoCert generates the cert with letsencrypt, this does not work on localhost
AutoCert bool
// CertFile location for the TLS server
CertFile string
// CertKey file location for the TLS server
CertKey string
}
TLSConfig contains config options for the HTTPS server