Documentation
¶
Index ¶
- func Decode(r *http.Request, v 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 Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode decodes the request body into v and calls its OK() function to validate the object.
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"`
HTTPListenPort int `yaml:"listenPort"`
HTTPServerReadTimeout time.Duration `yaml:"readTimeout"`
HTTPServerWriteTimeout time.Duration `yaml:"writeTimeout"`
HTTPServerIdleTimeout time.Duration `yaml:"idleTimeout"`
CompressionLevel int `yaml:"compressionLevel"`
}
Config for a HTTP server
func (*Config) RegisterFlags ¶
RegisterFlags adds the flags required to config the server
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