Documentation
¶
Index ¶
- Constants
- func EncodeResponseBody(body interface{}, w http.ResponseWriter)
- func EncodeResponseError(err string, debug error, statusCode int, w http.ResponseWriter)
- func EncodeResponseErrorBadRequest(err string, debug error, w http.ResponseWriter)
- func EncodeResponseErrorInternalServer(err string, debug error, w http.ResponseWriter)
- func EncodeResponseErrorUnauthorized(err string, debug error, w http.ResponseWriter)
- func ParsePathVar(varName string, ps *httprouter.Params) (value string, err error)
- func ParsePathVarInt(varName string, ps *httprouter.Params) (value int, err error)
- func ReadRequestBody(r *http.Request) ([]byte, error)
- type AuthenticationError
- type ErrorResponse
- type HTTPReciever
- type Handler
- type HandlerGroup
- type Server
- type Status
Constants ¶
const ( // HeaderContentType is a HTTP header name that states the structure of the // response body HeaderContentType = "Content-Type" // HeaderContentTypeValJSON is a value for the content type header for JSON. HeaderContentTypeValJSON = "application/json" )
const ( // ErrorAuthentication is the generic error message given when the user // failed to authenticate. ErrorAuthentication = "error authenticating user" // ErrorPathVariableParsing is the generic error message given when some path // variable could not be parsed properly. ErrorPathVariableParsing = "error parsing path variable" // ErrorRequestBodyReading is the generic error message given when HTTP // request body could not be read. ErrorRequestBodyReading = "error reading request body" // ErrorRequestBodyParsing is the generic error message given when HTTP // request body could not be parsed. ErrorRequestBodyParsing = "error parsing request body" // ErrorInternalServer is the generic error message given when an error was // encountered in the server. ErrorInternalServer = "error within server" )
Variables ¶
This section is empty.
Functions ¶
func EncodeResponseBody ¶
func EncodeResponseBody(body interface{}, w http.ResponseWriter)
EncodeResponseBody encodes the given value into the response body of the given ResponseWriter.
func EncodeResponseError ¶
func EncodeResponseError(err string, debug error, statusCode int, w http.ResponseWriter)
EncodeResponseError encodes an error response into the response body of the given ResponseWriter.
func EncodeResponseErrorBadRequest ¶
func EncodeResponseErrorBadRequest(err string, debug error, w http.ResponseWriter)
EncodeResponseErrorBadRequest encodes an error response with status code BadRequest.
func EncodeResponseErrorInternalServer ¶
func EncodeResponseErrorInternalServer(err string, debug error, w http.ResponseWriter)
EncodeResponseErrorInternalServer encodes an error response with status code InternalServerError.
func EncodeResponseErrorUnauthorized ¶
func EncodeResponseErrorUnauthorized(err string, debug error, w http.ResponseWriter)
EncodeResponseErrorUnauthorized encodes an error response with status code Unauthorized.
func ParsePathVar ¶
func ParsePathVar(varName string, ps *httprouter.Params) (value string, err error)
ParsePathVar returns the string value of a path variable with the given name.
func ParsePathVarInt ¶
func ParsePathVarInt(varName string, ps *httprouter.Params) (value int, err error)
ParsePathVarInt returns the int value of a path variable with the given name.
Types ¶
type AuthenticationError ¶
type AuthenticationError struct {
Debug string
}
AuthenticationError is raised when the user fails to authenticate.
func (*AuthenticationError) Error ¶
func (err *AuthenticationError) Error() string
type ErrorResponse ¶
type ErrorResponse struct {
Time *time.Time `json:"time"`
Error string `json:"error"`
Debug string `json:"debug"`
}
ErrorResponse represents an error message to be returned to the client if an error is encountered.
func ErrorResponseNew ¶
func ErrorResponseNew(err string, debug error) *ErrorResponse
ErrorResponseNew returns a new instance of errorResponse for the current time.
type HTTPReciever ¶
type HTTPReciever = func(http.ResponseWriter, *http.Request, httprouter.Params)
HTTPReciever is a type alias for functions that handle HTTP requests.
type Handler ¶
type Handler struct {
Method string
Path []string
Func HTTPReciever
ResponseHeaders map[string]string
}
Handler is a single HTTP request handler
func (*Handler) HandlerFunc ¶
func (h *Handler) HandlerFunc() func(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
HandlerFunc returns a HTTP handler function that implements the handler's logic.
func (*Handler) PathString ¶
PathString returns the full string form of the path of the handler.
type HandlerGroup ¶
type HandlerGroup interface {
Handlers() []Handler
}
HandlerGroup is a group of handlers that have some shared properties.
type Server ¶
type Server struct {
Router *httprouter.Router
Address string
}
Server represents the API controller layer.
func (*Server) HTTPServer ¶
HTTPServer returns a new http.Server object for the server.
func (*Server) RegisterHandler ¶
RegisterHandler registers the given handler with the server.
func (*Server) RegisterHandlerGroup ¶
func (s *Server) RegisterHandlerGroup(g HandlerGroup)
RegisterHandlerGroup registers all the handlers in the given handler group with the server
func (*Server) StatusHandler ¶
StatusHandler returns an endpoint handler that returns the status of the server.
type Status ¶
Status contains information about the API at the current time.
func CurrentStatus ¶
func CurrentStatus() *Status
CurrentStatus retrieves information about the API at the current time and returns it as an APIStatus object.