Documentation ¶
Index ¶
- Variables
- func NormalizePort(val string) string
- type Context
- type HandlerFunc
- type Map
- type Middleware
- type Server
- func (s *Server) Delete(path string, handler HandlerFunc)
- func (s *Server) Get(path string, handler HandlerFunc)
- func (s *Server) Patch(path string, handler HandlerFunc)
- func (s *Server) Post(path string, handler HandlerFunc)
- func (s *Server) Put(path string, handler HandlerFunc)
- func (s *Server) Start()
- func (s *Server) Use(middleware Middleware)
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBodyTooLarge = errors.New("request body too large")
View Source
var ErrInternalServer = errors.New("internal server error")
View Source
var ErrInvalidJSON = errors.New("invalid json")
Functions ¶
func NormalizePort ¶
Types ¶
type Context ¶
type Context struct { Request *http.Request Writer http.ResponseWriter Params httprouter.Params Logger *zap.Logger ResponseStatus int }
func (*Context) DecodeJSONBody ¶
func (*Context) GetQueryParam ¶
func (*Context) JSONResponse ¶
func (c *Context) JSONResponse(data interface{})
JSONResponse marshals the provided interface into JSON and writes it to the response writer If there is an error in marshalling the JSON, an internal server error is returned
type HandlerFunc ¶
type HandlerFunc func(*Context)
func CORS ¶
func CORS(next HandlerFunc) HandlerFunc
func SecurityHeaders ¶
func SecurityHeaders(next HandlerFunc) HandlerFunc
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
This implementation of middleware will enable middleware chaining
type Server ¶
type Server struct { Router *httprouter.Router Middlewares []Middleware Config *ServerConfig Logger *zap.Logger }
func NewServer ¶
func NewServer(config *ServerConfig) *Server
NewServer creates a new server instance
func (*Server) Delete ¶
func (s *Server) Delete(path string, handler HandlerFunc)
func (*Server) Get ¶
func (s *Server) Get(path string, handler HandlerFunc)
func (*Server) Patch ¶
func (s *Server) Patch(path string, handler HandlerFunc)
func (*Server) Post ¶
func (s *Server) Post(path string, handler HandlerFunc)
func (*Server) Put ¶
func (s *Server) Put(path string, handler HandlerFunc)
func (*Server) Use ¶
func (s *Server) Use(middleware Middleware)
Use adds a middleware to the server usage example: server.Use(stk.RequestLogger())
Click to show internal directories.
Click to hide internal directories.