Documentation ¶
Index ¶
- Variables
- func ParseRequestBodyJSON(r *http.Request, result interface{}) error
- func RespondJSON(ctx context.Context, w http.ResponseWriter, obj interface{}, ...)
- type CORSConfig
- type Error
- type HandlerFunc
- type Router
- func (rtr *Router) Get(route string, handlerFunc HandlerFunc)
- func (rtr *Router) Group(f func(*Router))
- func (rtr *Router) Handle(route string, h http.Handler)
- func (rtr *Router) Post(route string, handlerFunc HandlerFunc)
- func (rtr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (rtr Router) Use(middlewares ...func(http.Handler) http.Handler)
- func (rtr *Router) With(middlewares ...func(http.Handler) http.Handler) *Router
- type Server
- type ServerOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDefaultInternal represents the default internal server error ErrDefaultInternal = &Error{ Status: http.StatusInternalServerError, Code: "internal_error", Desc: "Something went wrong", } )
Functions ¶
func ParseRequestBodyJSON ¶
func RespondJSON ¶
Types ¶
type CORSConfig ¶
type CORSConfig struct {
// contains filtered or unexported fields
}
func NewCORSConfig ¶
func NewCORSConfig(origins []string) CORSConfig
type Error ¶
type Error struct { Status int `json:"-"` Code string `json:"code"` Desc string `json:"description"` }
Error represents a handler error. It contains web-related information such as HTTP status code, error code and error description
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Get ¶
func (rtr *Router) Get(route string, handlerFunc HandlerFunc)
func (*Router) Post ¶
func (rtr *Router) Post(route string, handlerFunc HandlerFunc)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an HTTP server
func NewServer ¶
func NewServer( watcher *watchdog.Client, corsCfg CORSConfig, readinessHF HandlerFunc, handler func(r *Router), opts ...ServerOption, ) *Server
NewServer initializes and returns an instance of Server
type ServerOption ¶
type ServerOption func(*Server)
ServerOption is an optional config used to modify the server's behaviour
func ServerAddr ¶
func ServerAddr(addr string) ServerOption
ServerAddr overrides the server's default address with the given addr.
func ServerProfilingDisabled ¶
func ServerProfilingDisabled() ServerOption
ServerProfilingDisabled disables pprof profiling.
func ServerReadTimeout ¶
func ServerReadTimeout(duration time.Duration) ServerOption
ServerReadTimeout overrides the server's default account timeout with the given one.
func ServerShutdownGrace ¶
func ServerShutdownGrace(duration time.Duration) ServerOption
ServerShutdownGrace overrides the server's default shutdown grace timeout with the given one.
func ServerWriteTimeout ¶
func ServerWriteTimeout(duration time.Duration) ServerOption
ServerWriteTimeout overrides the server's default write timeout with the given one.