Documentation ¶
Index ¶
- type AbstractController
- func (c *AbstractController) GetLog(r *http.Request) *gousu.Log
- func (c *AbstractController) Health() error
- func (c *AbstractController) Start() error
- func (c *AbstractController) Stop() error
- func (c *AbstractController) UseHost(host string)
- func (c *AbstractController) UsePort(port int)
- func (c *AbstractController) UseRouter(router chi.Router)
- func (c *AbstractController) WithExtra(r *http.Request, key string, value interface{}) *http.Request
- func (c *AbstractController) Wrap(clb HandlerFunction) func(w http.ResponseWriter, r *http.Request)
- type ContentType
- type HandlerFunction
- type IResponse
- func OptionalQueryParamBool(request *http.Request, name string) (null.Bool, IResponse)
- func OptionalQueryParamInt64(request *http.Request, name string) (null.Int, IResponse)
- func OptionalQueryParamString(request *http.Request, name string) (null.String, IResponse)
- func OptionalURLParamBool(request *http.Request, name string) (null.Bool, IResponse)
- func OptionalURLParamInt64(request *http.Request, name string) (null.Int, IResponse)
- func OptionalURLParamString(request *http.Request, name string) (null.String, IResponse)
- func QueryParamBool(request *http.Request, name string) (bool, IResponse)
- func QueryParamInt64(request *http.Request, name string) (int64, IResponse)
- func QueryParamString(request *http.Request, name string) (string, IResponse)
- func URLParamBool(request *http.Request, name string) (bool, IResponse)
- func URLParamInt64(request *http.Request, name string) (int64, IResponse)
- func URLParamInt64Slice(request *http.Request, name string) ([]int64, IResponse)
- func URLParamString(request *http.Request, name string) (string, IResponse)
- type Response
- func HTML(request *http.Request, body string) *Response
- func JSON(request *http.Request, obj interface{}) *Response
- func NewResponse(request *http.Request, statusCode int, contentType ContentType, body []byte) *Response
- func NewStreamResponse(request *http.Request, statusCode int, contentType ContentType, ...) *Response
- func Text(request *http.Request, body string) *Response
- func (r *Response) GetRequest() *http.Request
- func (r *Response) Log(log *gousu.Log)
- func (r *Response) WithDetailedMessage(detailedMessage string, args ...interface{}) *Response
- func (r *Response) WithHeader(key string, value string) *Response
- func (r *Response) WithStatusCode(statusCode int) *Response
- func (r *Response) WithoutLogging() *Response
- func (r *Response) Write(w http.ResponseWriter) IResponse
- type ResponseError
- func BadRequest(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
- func Forbidden(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
- func InternalServerError(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
- func NotFound(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
- func Unauthorized(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractController ¶
type AbstractController struct {
// contains filtered or unexported fields
}
func NewAbstractController ¶
func NewAbstractController( log *gousu.Log, ) *AbstractController
func (*AbstractController) GetLog ¶
func (c *AbstractController) GetLog(r *http.Request) *gousu.Log
func (*AbstractController) Health ¶
func (c *AbstractController) Health() error
Health checks if the api server has thrown unresolvable internal errors
func (*AbstractController) Start ¶
func (c *AbstractController) Start() error
Start starts the api server in a new go-func
func (*AbstractController) Stop ¶
func (c *AbstractController) Stop() error
Stop currently does nothing
func (*AbstractController) UseHost ¶
func (c *AbstractController) UseHost(host string)
func (*AbstractController) UsePort ¶
func (c *AbstractController) UsePort(port int)
func (*AbstractController) UseRouter ¶
func (c *AbstractController) UseRouter(router chi.Router)
func (*AbstractController) Wrap ¶
func (c *AbstractController) Wrap(clb HandlerFunction) func(w http.ResponseWriter, r *http.Request)
type ContentType ¶
type ContentType string
const ( ContentTypeApplicationJSON ContentType = "application/json" ContentTypeApplicationOctetStream ContentType = "application/octet-stream" ContentTypeApplicationPDF ContentType = "application/pdf" ContentTypeTextPlain ContentType = "text/plain" ContentTypeTextHTML ContentType = "text/html" ContentTypeTextCSV ContentType = "text/csv" ContentTypeImagePNG ContentType = "image/png" ContentTypeImageJPEG ContentType = "image/jpeg" ContentTypeImageBMP ContentType = "image/bmp" )
type HandlerFunction ¶
type HandlerFunction func(w http.ResponseWriter, r *http.Request) IResponse
type IResponse ¶
type IResponse interface { GetRequest() *http.Request Write(w http.ResponseWriter) IResponse Log(log *gousu.Log) }
func OptionalQueryParamBool ¶
OptionalQueryParamBool loads a parameter from the url's query and parses it as bool
If the parameter is not empty and not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False
func OptionalQueryParamInt64 ¶
OptionalQueryParamInt64 loads a parameter from the url's query and parses it as int64
If the parameter is not empty and not a valid int64 a BadRequest-Response is returned, else the response is nil
func OptionalQueryParamString ¶ added in v1.3.0
OptionalQueryParamString loads a parameter from the url's query
Response is always nil and only returned for compatiblity here
func OptionalURLParamBool ¶ added in v1.3.0
OptionalURLParamBool loads a parameter from the url and parses it as bool
If the parameter is not empty and not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False
func OptionalURLParamInt64 ¶ added in v1.3.0
OptionalURLParamInt64 loads a parameter from the url and parses it as int64
If the parameter is not empty and not a valid int64 a BadRequest-Response is returned, else the response is nil
func OptionalURLParamString ¶ added in v1.3.0
OptionalURLParamString loads a parameter from the url
Response is always nil and only returned for compatiblity here
func QueryParamBool ¶
QueryParamBool loads a parameter from the url's query and parses it as bool
If the parameter is not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False
func QueryParamInt64 ¶
QueryParamInt64 loads a parameter from the url's query and parses it as int64
If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil
func QueryParamString ¶ added in v1.3.0
QueryParamString loads a parameter from the url's query
If the parameter is empty a BadRequest-Response is returned, else the response is nil
func URLParamBool ¶
URLParamBool loads a parameter from the url and parses it as bool
If the parameter is not a valid bool a BadRequest-Response is returned, else the response is nil. Accepted values are 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False
func URLParamInt64 ¶
URLParamInt64 loads a parameter from the url and parses it as int64
If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil
func URLParamInt64Slice ¶ added in v1.3.0
URLParamInt64Slice loads a parameter from the url and parses it as a comma-separated list of int64
If the parameter is not a valid int64 a BadRequest-Response is returned, else the response is nil
type Response ¶
type Response struct { Request *http.Request StatusCode int Header http.Header ContentType ContentType Body []byte BodyReader io.Reader DetailedMessage string DisableLogging bool // contains filtered or unexported fields }
func NewResponse ¶
func NewStreamResponse ¶
func (*Response) GetRequest ¶
func (*Response) WithDetailedMessage ¶
func (*Response) WithHeader ¶ added in v1.5.0
func (*Response) WithStatusCode ¶
func (*Response) WithoutLogging ¶ added in v1.5.1
type ResponseError ¶
type ResponseError struct { Request *http.Request StatusCode int PublicMessage string DetailedError error }
func BadRequest ¶
func BadRequest(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
func Forbidden ¶
func Forbidden(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
func InternalServerError ¶
func InternalServerError(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
func NotFound ¶
func NotFound(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
func Unauthorized ¶
func Unauthorized(request *http.Request, detailedMessage string, args ...interface{}) *ResponseError
func (*ResponseError) GetRequest ¶
func (r *ResponseError) GetRequest() *http.Request
func (*ResponseError) Log ¶
func (r *ResponseError) Log(log *gousu.Log)
func (*ResponseError) Write ¶
func (r *ResponseError) Write(w http.ResponseWriter) IResponse