Documentation
¶
Index ¶
- Constants
- func Header(key, value string) func(http.Handler) http.Handler
- func Log(t logger.Type) func(http.Handler) http.Handler
- type APIError
- type APIResponse
- type Environment
- type HeaderHandler
- type Middleware
- type Router
- func (r *Router) Delete(path string, f func(w http.ResponseWriter, r *http.Request))
- func (r *Router) Get(path string, f func(w http.ResponseWriter, r *http.Request))
- func (r *Router) InternalRouter() *mux.Router
- func (r *Router) Post(path string, f func(w http.ResponseWriter, r *http.Request))
- func (r *Router) Put(path string, f func(w http.ResponseWriter, r *http.Request))
Constants ¶
const ( // API_PREFIX used for all available routes. API_PREFIX string = "/api" // API_VERSION included in all available routes. API_VERSION string = "/v1" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIError ¶
type APIError string
APIError informs about possible failures in requests.
const ( // RequestFailedError when service call fails. RequestFailedError APIError = "HTTP_REQUEST_FAILED" // ReadDataFailedError when response contains errors. ReadDataFailedError APIError = "READ_DATA_FAILED" // UnmarshalDataFailedError when unmarshal data from response fails. UnmarshalDataFailedError APIError = "UNMARSHAL_DATA_FAILED" )
type APIResponse ¶
APIResponse returned from endpoints in JSON form.
func NewAPIResponse ¶
func NewAPIResponse(msg string, code int) APIResponse
APIResponse is a default constructor of APIResponse.
func (APIResponse) Send ¶
func (a APIResponse) Send(resp http.ResponseWriter) error
Send marshaled APIError with given code.
type Environment ¶
Environment stores all components that should be shared between packages in application.
func NewEnvironment ¶
func NewEnvironment(logger logger.Type) *Environment
NewEnvironment is a default constructor for an Environment. It takes logger type as an argument.
type HeaderHandler ¶
type HeaderHandler struct {
// contains filtered or unexported fields
}
HeaderHandler acts as middleware adding headers.
func (HeaderHandler) ServeHTTP ¶
func (h HeaderHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTP serves HTML document.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware holds different chains of middleware and merges them as needed.
func (*Middleware) API ¶
func (m *Middleware) API(h http.HandlerFunc) http.Handler
API returns middleware chain containing common and api chain.
func (*Middleware) HTML ¶
func (m *Middleware) HTML(h http.HandlerFunc) http.Handler
HTML returns middleware chain containing common and html chain.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router enables defining API routes and assinging handlers.
func (*Router) InternalRouter ¶
InternalRouter enables accessing router used in implementation.