Documentation ¶
Index ¶
- Constants
- Variables
- func Handler(e *Endpoint, deps Dependencies) http.Handler
- type Dependencies
- type Endpoint
- type Endpoints
- type HTTPRequest
- func (req *HTTPRequest) Context() context.Context
- func (req *HTTPRequest) ID() string
- func (req *HTTPRequest) Logger() logger.Logger
- func (req *HTTPRequest) Params() interface{}
- func (req *HTTPRequest) Reporter() reporter.Reporter
- func (req *HTTPRequest) Response() request.Response
- func (req *HTTPRequest) Session() *auth.Session
- func (req *HTTPRequest) SetSession(s *auth.Session)
- func (req *HTTPRequest) SetUser(u *auth.User)
- func (req *HTTPRequest) Signature() string
- func (req *HTTPRequest) String() string
- func (req *HTTPRequest) User() *auth.User
- type HTTPResponse
- type ResponseError
- type RouteHandler
Constants ¶
const ( // ContentTypeJSON represents the content type of a JSON request ContentTypeJSON = "application/json" // ContentTypeMultipartForm represents the content type of a multipart request ContentTypeMultipartForm = "multipart/form-data" // ContentTypeForm represents the content type of a POST/PUT/PATCH request ContentTypeForm = "application/x-www-form-urlencoded" )
Variables ¶
var ErrMsgInvalidJSONPayload = "invalid JSON payload"
ErrMsgInvalidJSONPayload is the message representing a invalid json payload
Functions ¶
Types ¶
type Dependencies ¶
type Dependencies interface { // NewLogger creates a new logger using the provided logger creator NewLogger() (logger.Logger, error) // NewReporter creates a new reporter using the provided reporter Creator NewReporter() (reporter.Reporter, error) // DB returns the current SQL connection DB() db.Connection }
Dependencies represents all the dependencies needed by the router
type Endpoint ¶
type Endpoint struct { Verb string // Path is the path for the current component Path string // Handler is the handler to call Handler RouteHandler // Guard is the security system of an endpoint Guard *guard.Guard }
Endpoint represents an HTTP endpoint
type HTTPRequest ¶
type HTTPRequest struct {
// contains filtered or unexported fields
}
HTTPRequest represent a client request
func (*HTTPRequest) Context ¶
func (req *HTTPRequest) Context() context.Context
Context returns the context of the request
func (*HTTPRequest) Logger ¶
func (req *HTTPRequest) Logger() logger.Logger
Logger returns the logger used by the request
func (*HTTPRequest) Params ¶
func (req *HTTPRequest) Params() interface{}
Params returns the params needed by the endpoint
func (*HTTPRequest) Reporter ¶
func (req *HTTPRequest) Reporter() reporter.Reporter
Reporter returns the reporter used by the request
func (*HTTPRequest) Response ¶
func (req *HTTPRequest) Response() request.Response
Response returns the response of the request
func (*HTTPRequest) Session ¶
func (req *HTTPRequest) Session() *auth.Session
Session returns the session used to make the request
func (*HTTPRequest) SetSession ¶
func (req *HTTPRequest) SetSession(s *auth.Session)
SetSession sets the session object that was used to make the request
func (*HTTPRequest) SetUser ¶
func (req *HTTPRequest) SetUser(u *auth.User)
SetUser sets the user object that made the request
func (*HTTPRequest) Signature ¶
func (req *HTTPRequest) Signature() string
Signature returns the signature of the request Ex. POST /users
func (*HTTPRequest) String ¶
func (req *HTTPRequest) String() string
func (*HTTPRequest) User ¶
func (req *HTTPRequest) User() *auth.User
User returns the user that made the request
type HTTPResponse ¶
type HTTPResponse struct {
// contains filtered or unexported fields
}
HTTPResponse is a basic implementation of the HTTPResponse that uses a ResponseWriter
func NewResponse ¶
func NewResponse(writer http.ResponseWriter) *HTTPResponse
NewResponse creates a new response
func (*HTTPResponse) Created ¶
func (res *HTTPResponse) Created(obj interface{}) error
Created sends a http.StatusCreated response with a JSON object attached
func (*HTTPResponse) Error ¶
func (res *HTTPResponse) Error(e error, req request.Request)
Error sends an error to the client If the error is an instance of HTTPError, the returned code will match HTTPError.HTTPStatus(). It returns a 500 if no code has been set.
func (*HTTPResponse) Header ¶
func (res *HTTPResponse) Header() http.Header
Header returns the header object of the response
func (*HTTPResponse) NoContent ¶
func (res *HTTPResponse) NoContent()
NoContent sends a http.StatusNoContent response
func (*HTTPResponse) Ok ¶
func (res *HTTPResponse) Ok(obj interface{}) error
Ok sends a http.StatusOK response with a JSON object attached
type ResponseError ¶
type ResponseError struct { Error string `json:"error,omitempty"` Field string `json:"field,omitempty"` }
ResponseError represents the data sent the client when an error occurs
type RouteHandler ¶
RouteHandler is the function signature we nee