Documentation
¶
Index ¶
- Constants
- func BadRequest(r *Request, w http.ResponseWriter, e error)
- func Created(r *Request, w http.ResponseWriter)
- func Forbidden(r *Request, w http.ResponseWriter)
- func HandleError(r *Request, w http.ResponseWriter, e error)
- func InternalServerError(r *Request, w http.ResponseWriter, e error)
- func JSON(r *Request, w http.ResponseWriter, body interface{})
- func NoContent(r *Request, w http.ResponseWriter)
- func NotFound(r *Request, w http.ResponseWriter)
- func NotImplemented(r *Request, w http.ResponseWriter)
- func OK(r *Request, w http.ResponseWriter)
- func PrintArgs(r *http.Request)
- func QueryArgInt(r *http.Request, name string, defaultVal int) (val int)
- func QueryArgInt64(r *http.Request, name string, defaultVal int64) (val int64)
- func QueryArgString(r *http.Request, name string, defaultVal string) (val string)
- func URLParamInt64(r *http.Request, name string, defaultVal int64) (val int64)
- func URLParamString(r *http.Request, name string, defaultVal string) (val string)
- func Unauthorized(r *Request, w http.ResponseWriter)
- type ErrorResponse
- type HTTPMethodType
- type IResponseLogger
- type Request
- func (r *Request) Arg(name string, defaultVal string) string
- func (r *Request) ArgInt(name string, defaultVal int) int
- func (r *Request) ArgInt64(name string, defaultVal int64) int64
- func (r *Request) AuthKey() string
- func (r *Request) BodyJSON(obj interface{})
- func (r *Request) Header(name string) string
- func (r *Request) ToJSONString() string
- type Response
- func (s *Response) BadRequest(r *Request, w http.ResponseWriter, e error)
- func (s *Response) Created(r *Request, w http.ResponseWriter)
- func (s *Response) Forbidden(r *Request, w http.ResponseWriter)
- func (s *Response) HandleError(r *Request, w http.ResponseWriter, e error)
- func (s *Response) InternalServerError(r *Request, w http.ResponseWriter, e error)
- func (s *Response) JSON(r *Request, w http.ResponseWriter, body interface{})
- func (s *Response) NoContent(r *Request, w http.ResponseWriter)
- func (s *Response) NotFound(r *Request, w http.ResponseWriter)
- func (s *Response) NotImplemented(r *Request, w http.ResponseWriter)
- func (s *Response) OK(r *Request, w http.ResponseWriter)
- func (s *Response) Unauthorized(r *Request, w http.ResponseWriter)
- type UserLogActionType
Constants ¶
const AuthHeaderKey = "Authorization"
AuthHeaderKey is the name of the Authorization header
const AuthHeaderValuePrefix = "Bearer "
AuthHeaderValuePrefix is the start of the Authorization string (in the authorization header) used to authorize the request
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(r *Request, w http.ResponseWriter, e error)
BadRequest returns a bad request status (400)
func Created ¶
func Created(r *Request, w http.ResponseWriter)
Created returns a created status (201)
func Forbidden ¶
func Forbidden(r *Request, w http.ResponseWriter)
Forbidden returns a forbidden status (403)
func HandleError ¶
func HandleError(r *Request, w http.ResponseWriter, e error)
HandleError handles errors returned from the service layer and calls a api error handler to return the corresponding HTTP response
func InternalServerError ¶
func InternalServerError(r *Request, w http.ResponseWriter, e error)
InternalServerError returns a 500 server error response
func JSON ¶
func JSON(r *Request, w http.ResponseWriter, body interface{})
JSON Returns an ok status with json-encoded body
func NoContent ¶
func NoContent(r *Request, w http.ResponseWriter)
NoContent returns a noContent status (204)
func NotFound ¶
func NotFound(r *Request, w http.ResponseWriter)
NotFound returns a not-found status
func NotImplemented ¶
func NotImplemented(r *Request, w http.ResponseWriter)
NotImplemented shows a text response for not implemented method (501)
func QueryArgInt ¶
QueryArgInt checks the incoming request `r` for a query argument named `name` and if it exists, attempts to parse it to an integer If the argument does not exist, the value `defaultVal` is returned
func QueryArgInt64 ¶
QueryArgInt64 checks the incoming request `r` for a query argument named `name` and if it exists, attempts to parse it to an 64-bit integer If the argument does not exist, the value `defaultVal` is returned
func QueryArgString ¶
QueryArgString checks the incoming request `r` for a query argument named `name` and if it exists, returns it Else, it returns `defaultVal`
func URLParamInt64 ¶
URLParamInt64 returns an int64 value from a url parameter
func URLParamString ¶
URLParamString returns a string url parameter or the default if not found
func Unauthorized ¶
func Unauthorized(r *Request, w http.ResponseWriter)
Unauthorized returns an unauthorized status (401)
Types ¶
type ErrorResponse ¶
ErrorResponse is the structure of a response that is an error @model ErrorResponse
type HTTPMethodType ¶
type HTTPMethodType int
HTTPMethodType is the type of a method request
const ( // HTTPMethodUnknown is an unknown method type HTTPMethodUnknown HTTPMethodType = iota // HTTPMethodGet is the http method 'GET' HTTPMethodGet // HTTPMethodPost is the http method POST HTTPMethodPost // HTTPMethodPut is the http method PUT HTTPMethodPut // HTTPMethodDelete is the http method DELETE HTTPMethodDelete // HTTPMethodOptions is the http method OPTIONS HTTPMethodOptions // HTTPMethodHead is the http method HEAD HTTPMethodHead // HTTPMethodTrace is the http method TRACE HTTPMethodTrace // HTTPMethodPatch is the http method PATCH HTTPMethodPatch )
func HTTPMethodTypeFromString ¶
func HTTPMethodTypeFromString(method string) HTTPMethodType
HTTPMethodTypeFromString converts a method from a string to its method type
func (HTTPMethodType) Int64 ¶
func (h HTTPMethodType) Int64() int64
Int64 returns the int64 representation of the HTTPMethodType value
type IResponseLogger ¶
type IResponseLogger interface { // HandleError handles errors returned from the service layer and // calls a api error handler to return the corresponding HTTP response HandleError(r *Request, w http.ResponseWriter, e error) // NotImplemented shows a text response for not implemented method (501) NotImplemented(r *Request, w http.ResponseWriter) // InternalServerError returns a 500 server error response InternalServerError(r *Request, w http.ResponseWriter, e error) // NotFound returns a not-found status NotFound(r *Request, w http.ResponseWriter) // BadRequest returns a bad request status (400) BadRequest(r *Request, w http.ResponseWriter, e error) Unauthorized(r *Request, w http.ResponseWriter) // Forbidden returns a forbidden status (403) Forbidden(r *Request, w http.ResponseWriter) // NoContent returns a noContent status (204) NoContent(r *Request, w http.ResponseWriter) // Created returns a created status (201) Created(r *Request, w http.ResponseWriter) // JSON Returns an ok status with json-encoded body JSON(r *Request, w http.ResponseWriter, body interface{}) // OK Returns an ok status OK(r *Request, w http.ResponseWriter) }
IResponseLogger outlines methods for handling logging for API Responses
type Request ¶
type Request struct { Method string Path string Headers map[string]string Params map[string]string Body string ControllerMethod string ResponseCode int64 Error string UserID int64 RootRequest *http.Request `json:"-"` ActionType int64 }
Request is a request object
func NewRequest ¶
NewRequest is a factory method for a request
func (*Request) Arg ¶
Arg returns a string value for an argument in the request named `name` If it exists, returns it as a string Else, returns the `defaultVal`
func (*Request) ArgInt ¶
ArgInt returns an int value for an argument in the request named `name` If it exists, attempts to part it to a 64-bit integer Else, `defaultVal` is returned
func (*Request) ArgInt64 ¶
ArgInt64 returns an int64 value for an argument in the request named `name` If it exists, attempts to part it to a 64-bit integer Else, `defaultVal` is returned
func (*Request) BodyJSON ¶
func (r *Request) BodyJSON(obj interface{})
BodyJSON extracts the json from the body of a post or put request
func (*Request) ToJSONString ¶
ToJSONString returns a json string representation of the request
type Response ¶
type Response struct { }
Response is the API response handler
func (*Response) BadRequest ¶
func (s *Response) BadRequest(r *Request, w http.ResponseWriter, e error)
BadRequest returns a bad request status (400)
func (*Response) Created ¶
func (s *Response) Created(r *Request, w http.ResponseWriter)
Created returns a created status (201)
func (*Response) Forbidden ¶
func (s *Response) Forbidden(r *Request, w http.ResponseWriter)
Forbidden returns a forbidden status (403)
func (*Response) HandleError ¶
func (s *Response) HandleError(r *Request, w http.ResponseWriter, e error)
HandleError handles errors returned from the service layer and calls a api error handler to return the corresponding HTTP response
func (*Response) InternalServerError ¶
func (s *Response) InternalServerError(r *Request, w http.ResponseWriter, e error)
InternalServerError returns a 500 server error response
func (*Response) JSON ¶
func (s *Response) JSON(r *Request, w http.ResponseWriter, body interface{})
JSON Returns an ok status with json-encoded body
func (*Response) NoContent ¶
func (s *Response) NoContent(r *Request, w http.ResponseWriter)
NoContent returns a noContent status (204)
func (*Response) NotFound ¶
func (s *Response) NotFound(r *Request, w http.ResponseWriter)
NotFound returns a not-found status
func (*Response) NotImplemented ¶
func (s *Response) NotImplemented(r *Request, w http.ResponseWriter)
NotImplemented shows a text response for not implemented method (501)
func (*Response) OK ¶
func (s *Response) OK(r *Request, w http.ResponseWriter)
OK Returns an ok status
func (*Response) Unauthorized ¶
func (s *Response) Unauthorized(r *Request, w http.ResponseWriter)
Unauthorized returns an unauthorized status (401)
type UserLogActionType ¶
type UserLogActionType int64
UserLogActionType is the type of action in the user log
const ( // UserLogActionTypeAPI is an API Action Type UserLogActionTypeAPI UserLogActionType = iota + 1 // UserLogActionTypeClient is an API Action Type UserLogActionTypeClient )
func (UserLogActionType) Int64 ¶
func (lt UserLogActionType) Int64() int64
Int64 returns an int64 of the constant