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 interface { // http objects GetRequest() *http.Request GetWriter() http.ResponseWriter // get data from request GetParam(key string) string GetQueryParam(key string) string GetAllowedOrigins() []string DecodeJSONBody(v interface{}) error // set data for response Status(status int) Context SetHeader(string, string) RawResponse(raw []byte) JSONResponse(data interface{}) // logger Logger() *logrus.Logger }
type HandlerFunc ¶
type HandlerFunc func(Context)
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 *logrus.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.