xhttp

package
v0.0.0-...-73d6a9a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Module

func Module() fx.Option

func RegisterRouteMappings

func RegisterRouteMappings(router Router, routes RouteMappings, logger xlog.OptionalLogger)

RegisterRouteMappings register the given routes.

func RegisterSafeHandlers

func RegisterSafeHandlers(router Router, notFound NotFound, methodNotAllowed MethodNotAllowed, logger xlog.OptionalLogger)

func Start

func Start(_ context.Context, server HTTPServer, logger xlog.OptionalLogger) error

Start starts the Server.

func Stop

func Stop(ctx context.Context, server HTTPServer, logger xlog.OptionalLogger) error

Stop stop the Server

func WithMiddleware

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

noinspection GoUnusedExportedFunction

func WithPriority

func WithPriority(priority int) func(*Route)

noinspection GoUnusedExportedFunction

Types

type CompressQualifier

type CompressQualifier struct {
	fx.Out

	Middleware Middleware `name:"x_compress_middleware"`
}

func NewCompressMiddleware

func NewCompressMiddleware() CompressQualifier

type Config

type Config struct {
	Addr     string         `yaml:"addr"`
	Timeouts ConfigTimeouts `yaml:"timeouts"`
}

Config holds server configuration

func LoadConfig

func LoadConfig(params LoadConfigParams) (Config, error)

type ConfigTimeouts

type ConfigTimeouts struct {
	Read  time.Duration `yaml:"read"`
	Write time.Duration `yaml:"write"`
	Idle  time.Duration `yaml:"idle"`
}

type HTTPServer

type HTTPServer struct {
	fx.In

	Server *http.Server `name:"x_http_server"`
}

HTTPServer ir necessary to access the server by name

type HTTPServerQualifier

type HTTPServerQualifier struct {
	fx.Out

	Server *http.Server `name:"x_http_server"`
}

HTTPServerQualifier is necessary to give a name to the server

func NewHTTPServer

func NewHTTPServer(cfg Config, router Router) HTTPServerQualifier

NewHTTPServer returns a *http.Server with timeouts configured by Config.

type LoadConfigParams

type LoadConfigParams struct {
	fx.In

	Provider config.Provider `optional:"true"`
}

type MethodNotAllowed

type MethodNotAllowed struct {
	fx.In

	Handler http.Handler `name:"x_method_not_allowed_route_mapping" optional:"true"`
}

type MethodNotAllowedRouteMapping

type MethodNotAllowedRouteMapping struct {
	fx.Out

	Handler http.Handler `name:"x_method_not_allowed_route_mapping" optional:"true"`
}

type Middleware

type Middleware func(http.Handler) http.Handler

type NotFound

type NotFound struct {
	fx.In

	Handler http.Handler `name:"x_not_found_route_mapping" optional:"true"`
}

type NotFoundRouteMapping

type NotFoundRouteMapping struct {
	fx.Out

	Handler http.Handler `name:"x_not_found_route_mapping" optional:"true"`
}

type Route

type Route struct {
	// Priority The bigger, the sooner the route will be registered.
	// Important: The order of Routes with the same priority is not guarantee.
	Priority int

	// Method HTTP Method which the route must accept
	Method string

	// Path is the URL path
	// e.g: /hello/{name}
	Path string

	// Middleware a list of middleware that must be applied,
	// Important: Middleware are applied in the given order.
	Middleware []Middleware

	// Handler the standard go HTTP handler
	Handler http.Handler
}

Route holds everything the router needs to know to register a route into the container

func (*Route) String

func (r *Route) String() string

String returns a string representation of the route

type RouteMapping

type RouteMapping struct {
	fx.Out

	Route *Route `group:"x_route_mappings"`
}

RouteMapping Necessary to register more than one Route

func DELETE

func DELETE(path string, handler http.Handler, options ...func(*Route)) RouteMapping

func GET

func GET(path string, handler http.Handler, options ...func(*Route)) RouteMapping

func Handle

func Handle(method, path string, handler http.Handler, options ...func(*Route)) RouteMapping

func OPTIONS

func OPTIONS(path string, handler http.Handler, options ...func(*Route)) RouteMapping

func PATCH

func PATCH(path string, handler http.Handler, options ...func(*Route)) RouteMapping

func POST

func POST(path string, handler http.Handler, options ...func(*Route)) RouteMapping

func PUT

func PUT(path string, handler http.Handler, options ...func(*Route)) RouteMapping

type RouteMappings

type RouteMappings struct {
	fx.In

	Routes []*Route `group:"x_route_mappings"`
}

RouteMappings group routes to be registered by the Server. It is populated by the container with all routes from the group `routes`

type Router

type Router struct {
	fx.In

	Router *mux.Router `name:"x_http_router"`
}

type RouterQualifier

type RouterQualifier struct {
	fx.Out

	Router *mux.Router `name:"x_http_router"`
}

func NewEmptyRouter

func NewEmptyRouter() RouterQualifier

NewEmptyRouter creates a new HTTP server Mux and register the given routes.

Jump to

Keyboard shortcuts

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