router

package
v0.0.0-...-6907ca9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2018 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
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

View Source
var ErrMsgInvalidJSONPayload = "invalid JSON payload"

ErrMsgInvalidJSONPayload is the message representing a invalid json payload

Functions

func Handler

func Handler(e *Endpoint, deps Dependencies) http.Handler

Handler makes it possible to use a RouteHandler where a http.Handler is required

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 Endpoints

type Endpoints []*Endpoint

Endpoints represents a list of endpoint

func (Endpoints) Activate

func (endpoints Endpoints) Activate(router *mux.Router, deps Dependencies)

Activate adds the endpoints to the router

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) ID

func (req *HTTPRequest) ID() string

ID returns the ID 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

type RouteHandler func(request.Request) error

RouteHandler is the function signature we nee

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL