http

package
v0.0.0-...-4b56e16 Latest Latest
Warning

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

Go to latest
Published: May 11, 2017 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FacadeWrapper = &larago.Facade{}

FacadeWrapper for facade.

Functions

This section is empty.

Types

type ArgsInjector

type ArgsInjector interface {
	// Injects custom params to for the action.
	Inject(params []interface{}, request *Request) ([]interface{}, error)
}

ArgsInjector uses as an external source of arguments that can be injected in the route action handler.

type BindingCallback

type BindingCallback func(param string) (interface{}, error)

BindingCallback is a function to resolve binded param value.

type CommandDown

type CommandDown struct {
	Application *larago.Application
	Logger      *logger.Logger
}

CommandDown to apply DB changes.

func (*CommandDown) GetCommand

func (c *CommandDown) GetCommand() cli.Command

GetCommand for the cli to register.

func (*CommandDown) Handle

func (c *CommandDown) Handle(args cli.Args) error

Handle command.

type CommandRoutes

type CommandRoutes struct {
	Router *Router
	Logger *logger.Logger
}

CommandRoutes to apply DB changes.

func (*CommandRoutes) GetCommand

func (c *CommandRoutes) GetCommand() cli.Command

GetCommand for the cli to register.

func (*CommandRoutes) Handle

func (c *CommandRoutes) Handle(args cli.Args) error

Handle command.

type CommandServe

type CommandServe struct {
	Router *Router
	Config *larago.ConfigRepository
	// contains filtered or unexported fields
}

CommandServe command.

func (*CommandServe) GetCommand

func (c *CommandServe) GetCommand() cli.Command

GetCommand for the cli to register.

func (*CommandServe) Handle

func (c *CommandServe) Handle(args cli.Args) error

Handle command.

type CommandUp

type CommandUp struct {
	Application *larago.Application
	Logger      *logger.Logger
}

CommandUp to apply DB changes.

func (*CommandUp) GetCommand

func (c *CommandUp) GetCommand() cli.Command

GetCommand for the cli to register.

func (*CommandUp) Handle

func (c *CommandUp) Handle(args cli.Args) error

Handle command.

type ErrorsHandler

type ErrorsHandler struct {
	Logger                    *logger.Logger
	Debug                     bool `di:"Config.App.Debug"`
	ValidationErrorsConverter validation.ErrorsConverter
}

ErrorsHandler to handle errors during http calls.

func (*ErrorsHandler) Render

func (h *ErrorsHandler) Render(request *Request, err error) responses.Response

Render error to the client

func (*ErrorsHandler) Report

func (h *ErrorsHandler) Report(err error)

Report error to logger.

type ErrorsHandlerInterface

type ErrorsHandlerInterface interface {
	// Report error to logger.
	Report(err error)

	// Render error to return to the client.
	Render(request *Request, err error) responses.Response
}

ErrorsHandlerInterface for every handler to resolve errors during http calls..

type FormRequestValidator

type FormRequestValidator interface {
	ValidateForm() error
}

FormRequestValidator interface for form requests.

type GroupRoute

type GroupRoute struct {
	Path        string
	Middlewares []Middleware
}

GroupRoute struct.

func NewGroupRoute

func NewGroupRoute(path string) *GroupRoute

NewGroupRoute constructor.

func (*GroupRoute) Middleware

func (r *GroupRoute) Middleware(middleware ...Middleware) *GroupRoute

Middleware sets middleware for GroupRoute.

type Handler

type Handler func(request *Request) responses.Response

Handler function.

type JSONRequestValidator

type JSONRequestValidator interface {
	ValidateJSON() error
}

JSONRequestValidator interface for json requests.

type Middleware

type Middleware interface {
	// Handle request.
	Handle(request *Request, next Handler) responses.Response
}

Middleware interface.

type ParamsRequestValidator

type ParamsRequestValidator interface {
	ValidateParams() error
}

ParamsRequestValidator interface for url params.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

Pipeline struct.

func NewPipeline

func NewPipeline(container container.Interface) *Pipeline

NewPipeline constructor.

func (*Pipeline) Send

func (p *Pipeline) Send(request *Request) *Pipeline

Send value througn every middleware.

func (*Pipeline) Then

func (p *Pipeline) Then(last Handler) (response responses.Response)

Then run pipeline with the last handler.

func (*Pipeline) Through

func (p *Pipeline) Through(middleware []Middleware) *Pipeline

Through what pipes run passable.

type QueryRequestValidator

type QueryRequestValidator interface {
	ValidateQuery() error
}

QueryRequestValidator interface for query.

type Request

type Request struct {
	Route    *Route
	Params   httprouter.Params
	Bindings []interface{}
	// contains filtered or unexported fields
}

Request handles http request.

func NewRequest

func NewRequest(netRequest *net_http.Request) *Request

NewRequest constructor.

func (*Request) BaseRequest

func (r *Request) BaseRequest() *net_http.Request

BaseRequest returns base net/http request.

func (*Request) Cookie

func (r *Request) Cookie(name string) string

Cookie returns cookie value.

func (*Request) FormValues

func (r *Request) FormValues() url.Values

FormValues returns all form values.

func (*Request) HasCookie

func (r *Request) HasCookie(name string) bool

HasCookie checks if cookie was sent.

func (*Request) Header

func (r *Request) Header(name string) string

Header returns header value.

func (*Request) HeaderContains

func (r *Request) HeaderContains(header, substring string) bool

HeaderContains checks if header contains requested substring.

func (*Request) IP

func (r *Request) IP() string

IP tries to return real client IP.

func (*Request) IsAjax

func (r *Request) IsAjax() bool

IsAjax checks if request was made via ajax.

func (*Request) Method

func (r *Request) Method() string

Method returns method name.

func (*Request) Param

func (r *Request) Param(name string) interface{}

Param returns route param.

func (*Request) ParamValues

func (r *Request) ParamValues() url.Values

ParamValues returns all param values in url.Values format.

func (*Request) Query

func (r *Request) Query() url.Values

Query returns query params.

func (*Request) ReadForm

func (r *Request) ReadForm(target interface{}) error

ReadForm unmarshal form request to the structure.

func (*Request) ReadJSON

func (r *Request) ReadJSON(target interface{}) error

ReadJSON unmarshal json request to the structure.

func (*Request) ReadParams

func (r *Request) ReadParams(target interface{}) error

ReadParams unmarshal url params to the structure.

func (*Request) ReadQuery

func (r *Request) ReadQuery(target interface{}) error

ReadQuery unmarshal query to the structure.

func (*Request) Referer

func (r *Request) Referer() string

Referer returns referer from header.

func (*Request) URL

func (r *Request) URL() string

URL returns requested URL.

func (*Request) WantsHTML

func (r *Request) WantsHTML() bool

WantsHTML checks if client wants HTML answer.

func (*Request) WantsJSON

func (r *Request) WantsJSON() bool

WantsJSON checks if client wants JSON answer.

func (*Request) WantsPlainText

func (r *Request) WantsPlainText() bool

WantsPlainText checks if client wants plain text answer.

type RequestsInjector

type RequestsInjector struct{}

RequestsInjector populates and validates

func (*RequestsInjector) Inject

func (rv *RequestsInjector) Inject(params []interface{}, request *Request) ([]interface{}, error)

Inject custom params to for the action.

type Route

type Route struct {
	Method      string
	Path        string
	Name        string
	Middlewares []Middleware
	Handler     interface{}
	ToValidate  []validation.SelfValidator
}

Route struct.

func NewRoute

func NewRoute(method string, path string) *Route

NewRoute constructor.

func (*Route) Action

func (r *Route) Action(handler interface{}) *Route

Action to use.

func (*Route) As

func (r *Route) As(name string) *Route

As name.

func (*Route) Middleware

func (r *Route) Middleware(middleware ...Middleware) *Route

Middleware sets middleware for route.

func (*Route) Validate

func (r *Route) Validate(requests ...validation.SelfValidator) *Route

Validate request.

type RouteParamsInjector

type RouteParamsInjector struct{}

RouteParamsInjector injects raw route params.

func (*RouteParamsInjector) Inject

func (i *RouteParamsInjector) Inject(params []interface{}, request *Request) ([]interface{}, error)

Inject custom params to for the action.

type Router

type Router struct {
	// Dependencies
	Container     *container.Container
	Logger        *logger.Logger
	Events        *EventBus.EventBus
	ErrorsHandler ErrorsHandlerInterface
	Config        larago.Config
	// contains filtered or unexported fields
}

Router struct.

func Facade

func Facade() *Router

Facade for router.

func NewRouter

func NewRouter() *Router

NewRouter constructor.

func (*Router) Bind

func (r *Router) Bind(param string, callback BindingCallback)

Bind route param to the specified callback return value.

func (*Router) Bootstrap

func (r *Router) Bootstrap() *Router

Bootstrap router to be ready to handle requests.

func (*Router) DELETE

func (r *Router) DELETE(path string) *Route

DELETE request.

func (*Router) GET

func (r *Router) GET(path string) *Route

GET request.

func (*Router) GetHTTPRouter

func (r *Router) GetHTTPRouter() *httprouter.Router

GetHTTPRouter returns httprouter instance.

func (*Router) GetMiddleware

func (r *Router) GetMiddleware() []Middleware

GetMiddleware returns all glbally registered middleware.

func (*Router) GetRoutes

func (r *Router) GetRoutes() []*Route

GetRoutes returns all registered routes.

func (*Router) Group

func (r *Router) Group(path string, callback func(), middleware ...Middleware)

Group routes.

func (*Router) Listen

func (r *Router) Listen(listen string) error

Listen to requests. Do not forget to run Bootstrap in order to prepare and set routes.

func (*Router) Middleware

func (r *Router) Middleware(middleware ...Middleware) *Router

Middleware sets global middleware to run over every request.

func (*Router) PATCH

func (r *Router) PATCH(path string) *Route

PATCH request.

func (*Router) POST

func (r *Router) POST(path string) *Route

POST request.

func (*Router) PUT

func (r *Router) PUT(path string) *Route

PUT request.

func (*Router) SetArgsInjectors

func (r *Router) SetArgsInjectors(injectors ...ArgsInjector)

SetArgsInjectors sets additional components that can inject more custom arguments to route action handler.

func (*Router) SetMethodNotAllowedHandler

func (r *Router) SetMethodNotAllowedHandler(handler net_http.HandlerFunc) *Router

SetMethodNotAllowedHandler allowes to set custom MethodNotAllowed handler.

func (*Router) SetNotFoundHandler

func (r *Router) SetNotFoundHandler(handler net_http.HandlerFunc) *Router

SetNotFoundHandler allowes to set custom NotFound handler.

type ServiceProvider

type ServiceProvider struct{}

ServiceProvider struct.

func (*ServiceProvider) Register

func (p *ServiceProvider) Register(application *larago.Application)

Register service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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