Documentation
¶
Overview ¶
Package server provides an http server.
Index ¶
- func Response(ctx context.Context, w http.ResponseWriter, err error)
- type Config
- func (c Config) AllowedHeaders() []string
- func (c Config) AllowedMethods() []string
- func (c Config) AllowedOrigins() []string
- func (c Config) MTLSEnabled() bool
- func (c Config) PprofEnabled() bool
- func (c Config) ReadTimeout() time.Duration
- func (c Config) ServerAddr() string
- func (c Config) ShutdownTimeout() time.Duration
- func (c Config) TLSCACert() string
- func (c Config) TLSCert() string
- func (c Config) TLSKey() string
- func (c Config) ToOptions() []Option
- func (c Config) WriteTimeout() time.Duration
- type Option
- func WithAddr(addr string) Option
- func WithCORSAllowedHeaders(headers []string) Option
- func WithCORSAllowedMethods(methods []string) Option
- func WithCORSAllowedOrigins(origins []string) Option
- func WithCORSOptions(c *cors.Options) Option
- func WithMTLSEnabled(enabled bool) Option
- func WithReadTimeout(timeout time.Duration) Option
- func WithShutdownTimeout(timeout time.Duration) Option
- func WithTLSCert(cert, key string) Option
- func WithTLSClientCACert(cacert string) Option
- func WithTLSConfig(cfg *tls.Config) Option
- func WithWriteTimeout(timeout time.Duration) Option
- type ResponseError
- type Server
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v0.2.4
type Config struct {
// contains filtered or unexported fields
}
Config holds the configuration information for the restful api server.
func (Config) AllowedHeaders ¶ added in v0.2.4
AllowedHeaders returns a string of Allowed Headers passed to the CORS middleware.
func (Config) AllowedMethods ¶ added in v0.2.4
AllowedMethods returns a string of Allowed Methods passed to the CORS middleware.
func (Config) AllowedOrigins ¶ added in v0.2.4
AllowedOrigins returns a string of Allowed Origins passed to the CORS middleware.
func (Config) MTLSEnabled ¶ added in v0.2.4
MTLSEnabled returns true if MTLS is enabled.
func (Config) PprofEnabled ¶ added in v0.2.11
PprofEnabled returns true when pprof should be enabled.
func (Config) ReadTimeout ¶ added in v0.2.5
ReadTimeout returns the server read timeout.
func (Config) ServerAddr ¶ added in v0.2.4
ServerAddr returns the network address the server will listen on.
func (Config) ShutdownTimeout ¶ added in v0.2.5
ShutdownTimeout returns the server shutdown timeout.
func (Config) ToOptions ¶ added in v0.2.7
ToOptions converts the configuration to a list of options.
func (Config) WriteTimeout ¶ added in v0.2.5
WriteTimeout returns the server write timeout.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option provides options for configuring the creation of a http server.
func WithCORSAllowedHeaders ¶ added in v0.2.5
With CORSAllowedHeaders will configure the CORS allowed headers.
func WithCORSAllowedMethods ¶ added in v0.2.5
With CORSAllowedMethods will configure the CORS allowed methods.
func WithCORSAllowedOrigins ¶ added in v0.2.5
With CORSAllowedOrigins will configure the CORS allowed origins.
func WithCORSOptions ¶ added in v0.2.4
WithCORSOptions will configure the server with the CORS options.
func WithMTLSEnabled ¶ added in v0.2.4
WithMTLSEnabled when set to true, enabled mutual TLS.
func WithReadTimeout ¶ added in v0.0.15
WithReadTimeout sets the http server read timeout.
func WithShutdownTimeout ¶
WithShutdownTimeout sets the timout for shutting down the server.
func WithTLSCert ¶ added in v0.2.4
WithTLSCert provides the file name of the public TLS certificate and key.
func WithTLSClientCACert ¶ added in v0.2.4
WithTLSClientCACert provides the file name of the client CA public certificate.
func WithTLSConfig ¶ added in v0.2.4
WithTLSConfig will configure the server to require TLS.
func WithWriteTimeout ¶ added in v0.0.15
WithWriteTimeout sets the http server read timeout.
type ResponseError ¶
type ResponseError struct {
// Status is the http status code applicable to this problem.
Status int `json:"status"`
// Detail is a human-readable explanation specific to this occurrence of
// the problem.
Detail string `json:"detail,omitempty"`
}
ResponseError provides additional information about problems encounted while performing an operation. See: https://jsonapi.org/format/#error-objects
swagger:response ResponseError
func (ResponseError) Error ¶
func (e ResponseError) Error() string
Error translates the error to a string.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an HTTP server.
func (Server) Middleware ¶
func (s Server) Middleware(mw ...mux.MiddlewareFunc)
Middleware installs the given middleware with the router.
type Service ¶
type Service interface {
// Register will register this service with the given router.
Register(router *mux.Router)
// Name provides the name of the service.
Name() string
// Shutdown allows the service to stop any long running background processes it
// may have.
Shutdown(context.Context)
}
Service defines the methods required by the Server to register with the service with the router.