Documentation
¶
Index ¶
- Variables
- func InitLogger(exitOnFatal bool)
- func ReadJSON(r io.Reader, v interface{}) interface{}
- func SendJSON(w http.ResponseWriter, v interface{})
- func SendJSONWithStatus(w http.ResponseWriter, v interface{}, s int)
- func SendStatus(w http.ResponseWriter, s int)
- type HTTPContext
- func (ctx *HTTPContext) GetAttribute(key string) interface{}
- func (ctx *HTTPContext) GetParam(p string) string
- func (ctx *HTTPContext) SendJSON(v interface{})
- func (ctx *HTTPContext) SendJSONWithStatus(v interface{}, s int)
- func (ctx *HTTPContext) SendStatus(s int)
- func (ctx *HTTPContext) SetAttribute(key string, attr interface{})
- type HTTPInterceptor
- type HealthcheckController
- type IHttpController
- type RestRouter
- func (r *RestRouter) Delete(path string, handle func(HTTPContext), v interface{}, ...)
- func (r *RestRouter) Get(path string, handle func(HTTPContext), interceptors ...HTTPInterceptor)
- func (r *RestRouter) Post(path string, handle func(HTTPContext), v interface{}, ...)
- func (r *RestRouter) Put(path string, handle func(HTTPContext), v interface{}, ...)
- type Router
- type Server
Constants ¶
This section is empty.
Variables ¶
var Logger *logmatic.Logger
Logger provides application-wide logging
Functions ¶
func InitLogger ¶
func InitLogger(exitOnFatal bool)
InitLogger initializes the application-wide logger
func SendJSON ¶
func SendJSON(w http.ResponseWriter, v interface{})
SendJSON converts the given interface into JSON and writes to the provided stream.
func SendJSONWithStatus ¶ added in v0.5.1
func SendJSONWithStatus(w http.ResponseWriter, v interface{}, s int)
SendJSONWithStatus writes a JSON response body to the provided stream, along with the specified status code.
func SendStatus ¶
func SendStatus(w http.ResponseWriter, s int)
SendStatus writes the given HTTP status code into the provided response stream.
Types ¶
type HTTPContext ¶
type HTTPContext struct { Response http.ResponseWriter Request *http.Request Body interface{} // contains filtered or unexported fields }
HTTPContext provides utility functions for HTTP requests/responses
func (*HTTPContext) GetAttribute ¶
func (ctx *HTTPContext) GetAttribute(key string) interface{}
GetAttribute returns the context-scoped value for the given key
func (*HTTPContext) GetParam ¶
func (ctx *HTTPContext) GetParam(p string) string
GetParam obtains the given parameter key from the request parameters.
func (*HTTPContext) SendJSON ¶
func (ctx *HTTPContext) SendJSON(v interface{})
SendJSON converts the given interface into JSON and writes to the response.
func (*HTTPContext) SendJSONWithStatus ¶ added in v0.5.1
func (ctx *HTTPContext) SendJSONWithStatus(v interface{}, s int)
SendJSONWithStatus writes a JSON response body to the response, along with the specified status code.
func (*HTTPContext) SendStatus ¶
func (ctx *HTTPContext) SendStatus(s int)
SendStatus writes the given HTTP status code into the response.
func (*HTTPContext) SetAttribute ¶
func (ctx *HTTPContext) SetAttribute(key string, attr interface{})
SetAttribute sets the context-scoped value for the given key
type HTTPInterceptor ¶
type HTTPInterceptor func(ctx HTTPContext) bool
HTTPInterceptor allows for pre-processing request handlers ex. an authentication interceptor could verify a user session
type HealthcheckController ¶ added in v0.6.0
type HealthcheckController struct { }
func (HealthcheckController) Load ¶ added in v0.6.0
func (c HealthcheckController) Load(router *Router)
type IHttpController ¶
type IHttpController interface {
Load(router *Router)
}
IHttpController represents a REST API that can be loaded into a router
type RestRouter ¶ added in v0.4.0
RestRouter represents a router for a specific REST API
func (*RestRouter) Delete ¶ added in v0.4.0
func (r *RestRouter) Delete(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor)
Delete handles DELETE HTTP requests for the given path
func (*RestRouter) Get ¶ added in v0.4.0
func (r *RestRouter) Get(path string, handle func(HTTPContext), interceptors ...HTTPInterceptor)
Get handles GET HTTP requests for the given path
func (*RestRouter) Post ¶ added in v0.4.0
func (r *RestRouter) Post(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor)
Post handles POST HTTP requests for the given path
func (*RestRouter) Put ¶ added in v0.4.0
func (r *RestRouter) Put(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor)
Put handles PUT HTTP requests for the given path
type Router ¶
Router maintains routing paths for a single REST API
func (*Router) NewRestRouter ¶ added in v0.4.0
func (r *Router) NewRestRouter(path string) *RestRouter
NewRestRouter initializes a new REST router on at the given path
type Server ¶
type Server struct { Port int BasePath string ExitOnFatal bool // contains filtered or unexported fields }
Server represents a REST API server container Default port is 8080 Default path is /api
func NewServer ¶
func NewServer(controllers ...IHttpController) *Server
NewServer creates a route-based REST API server instance
func (*Server) AutoMigrate ¶ added in v0.5.0
func (s *Server) AutoMigrate(models ...interface{})
func (*Server) Start ¶
func (s *Server) Start()
Start initializes the API and starts running on the specified port Blocks on current thread
func (*Server) UseHealthcheck ¶ added in v0.6.0
func (s *Server) UseHealthcheck()