net

package
v0.0.0-...-a16d91a Latest Latest
Warning

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

Go to latest
Published: May 21, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(*RequestRuntime) HandlerResult

Handler much like http.HandlerFunc, these are used as "route" handlers by the ServerRuntime

type HandlerResult

type HandlerResult struct {
	Errors   []error
	Results  ResultList
	Metadata map[string]interface{}
	Redirect string
	NoRender bool
	Status   int
}

HandlerResult public contract between routes and the server runtime for consistent rendering

type JSONRenderer

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

JSONRenderer exposes a `Renderer` interface for rendering `HandlerResult`s in json

func (*JSONRenderer) Render

func (js *JSONRenderer) Render(response http.ResponseWriter, result HandlerResult) error

Render uses a response writer and a `HandlerResult` to serialize the result in a json-api like format

type Metadata

type Metadata map[string]interface{}

Metadata is a basic string/interface map interface

type Multiplexer

type Multiplexer interface {
	MatchRequest(*http.Request) (bool, url.Values, Handler)
}

Multiplexer defines an interface that returns a handler, set of values and a boolean value indicating if a route has been found that matches the provided request.

type Renderer

type Renderer interface {
	Render(http.ResponseWriter, HandlerResult) error
}

Renderer defines the interface used by the `ServerRuntime` to render `HandlerResult`s returned by route handlers

type RequestRuntime

type RequestRuntime struct {
	url.Values
	WebsocketUpgrader
	bg.ChannelPublisher
	*logging.Logger
	*http.Request
	// contains filtered or unexported fields
}

RequestRuntime is used by the ServerRuntime to expose per-request packages of shared system interfaces

func (*RequestRuntime) ContentType

func (runtime *RequestRuntime) ContentType() string

ContentType returns the request content type from the inbound request.

func (*RequestRuntime) GetQueryParam

func (runtime *RequestRuntime) GetQueryParam(queryParam string) string

GetQueryParam returns a parsed url.Values struct from the request query params.

func (*RequestRuntime) HeaderValue

func (runtime *RequestRuntime) HeaderValue(key string) string

HeaderValue returns value for the given header key.

func (*RequestRuntime) LogicError

func (runtime *RequestRuntime) LogicError(message string) HandlerResult

LogicError will wrap the provided strin the appropriate error prefix and return a HandlerResult

func (*RequestRuntime) ReadBody

func (runtime *RequestRuntime) ReadBody(target interface{}) error

ReadBody will attempt to fill the provided interface with values from the http request

func (*RequestRuntime) ServerError

func (runtime *RequestRuntime) ServerError() HandlerResult

ServerError returns a HandlerResult w/ the standardized server error response text

func (*RequestRuntime) Websocket

func (runtime *RequestRuntime) Websocket() (defs.Streamer, error)

Websocket attempts to updrade the request to a websocket connection

type ResultList

type ResultList interface{}

ResultList is the array of items returned by a handler that will be rendered in the

type RouteConfig

type RouteConfig struct {
	Method  string
	Pattern *regexp.Regexp
}

RouteConfig defines a simple structure composed of the http method and a regular expression path matcher

type RouteConfigMapMatcher

type RouteConfigMapMatcher map[RouteConfig]Handler

RouteConfigMapMatcher is simply a map between a route configuration and the handler function

func (*RouteConfigMapMatcher) MatchRequest

func (list *RouteConfigMapMatcher) MatchRequest(request *http.Request) (bool, url.Values, Handler)

MatchRequest implements the net.Multiplexer interface.

type ServerRuntime

type ServerRuntime struct {
	WebsocketUpgrader
	Multiplexer
	bg.ChannelPublisher
	*logging.Logger
	ApplicationVersion string
}

ServerRuntime defines the object that implments the http.Handler interface used during application startup to open the http server. It is also responsible for matching inbound requests with it's embedded routelist and creating the request runtime to be sent into the matching route handler.

func (*ServerRuntime) ServeHTTP

func (runtime *ServerRuntime) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

ServerHTTP implmentation of the http.Handler interface method

type WebsocketUpgrader

type WebsocketUpgrader interface {
	UpgradeWebsocket(http.ResponseWriter, *http.Request, http.Header) (defs.Streamer, error)
}

WebsocketUpgrader defines an interface that upgrades an http request to a streamer interface.

Jump to

Keyboard shortcuts

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