Documentation
¶
Index ¶
- func Decode(w http.ResponseWriter, r *http.Request, dst interface{}) error
- func HandleMethodNotAllowed(logger *zap.Logger) http.HandlerFunc
- func HandleNotFound(logger *zap.Logger) http.HandlerFunc
- func SendRESTError(w http.ResponseWriter, r *http.Request, logger *zap.Logger, restErr *Error)
- func SendResponse(w http.ResponseWriter, r *http.Request, logger *zap.Logger, status int, ...)
- func TokenFromHeader(r *http.Request) string
- type Config
- type Error
- type MalformedRequest
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(w http.ResponseWriter, r *http.Request, dst interface{}) error
Decode tries to decode the request body into dst and calls its OK() function to validate the object. It returns an error if: - the content-type does not contain "application/json" - body is smaller than 1MB - any unknown fields were set - deserialization fails - the OK() method returns an error
func HandleMethodNotAllowed ¶
func HandleMethodNotAllowed(logger *zap.Logger) http.HandlerFunc
HandleMethodNotAllowed returns a handler func to respond to routes requested with the wrong verb a REST compliant error message
func HandleNotFound ¶
func HandleNotFound(logger *zap.Logger) http.HandlerFunc
HandleNotFound returns a handler func to respond to non existent routes with a REST compliant error message
func SendRESTError ¶
SendRESTError accepts a REST error which can be send to the user
func SendResponse ¶
func SendResponse(w http.ResponseWriter, r *http.Request, logger *zap.Logger, status int, data interface{})
SendResponse tries to send your data as JSON. If this fails it will print REST compliant errors
func TokenFromHeader ¶
TokenFromHeader tries to retreive the token string from the "Authorization" reqeust header: "Authorization: BEARER T".
Types ¶
type Config ¶
type Config struct {
ServerGracefulShutdownTimeout time.Duration `yaml:"gracefulShutdownTimeout"`
HTTPListenAddress string `yaml:"listenAddress"`
HTTPListenPort int `yaml:"listenPort"`
HTTPServerReadTimeout time.Duration `yaml:"readTimeout"`
HTTPServerWriteTimeout time.Duration `yaml:"writeTimeout"`
HTTPServerIdleTimeout time.Duration `yaml:"idleTimeout"`
CompressionLevel int `yaml:"compressionLevel"`
BasePath string `yaml:"basePath"`
SetBasePathFromXForwardedPrefix bool `yaml:"setBasePathFromXForwardedPrefix"`
StripPrefix bool `yaml:"stripPrefix"`
}
Config for a HTTP server
func (*Config) RegisterFlags ¶
RegisterFlags adds the flags required to config the server
func (*Config) SetDefaults ¶ added in v0.4.0
func (c *Config) SetDefaults()
type Error ¶
type Error struct {
Err error `json:"-"`
Status int `json:"statusCode"`
Message string `json:"message"`
InternalLogs []zapcore.Field `json:"-"`
IsSilent bool `json:"-"`
}
Error must be created to issue a REST compliant error
type MalformedRequest ¶ added in v0.5.0
func (*MalformedRequest) Error ¶ added in v0.5.0
func (mr *MalformedRequest) Error() string