server

package
v0.0.0-...-20aadb4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 17 Imported by: 9 modules, 83 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// HTTP methods
	PUT     = "PUT"
	GET     = "GET"
	POST    = "POST"
	HEAD    = "HEAD"
	PATCH   = "PATCH"
	DELETE  = "DELETE"
	OPTIONS = "OPTIONS"

	// MIME
	MIMEApplicationJSON            = "application/json"
	MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
	MIMEMultipartForm              = "multipart/form-data"

	// Headers
	HeaderOrigin        = "Origin"
	HeaderAccept        = "Accept"
	HeaderVary          = "Vary"
	HeaderCookie        = "Cookie"
	HeaderSetCookie     = "Set-Cookie"
	HeaderUpgrade       = "Upgrade"
	HeaderContentType   = "Content-Type"
	HeaderLocation      = "Location"
	HeaderAuthorization = "Authorization"

	// Access control
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"
)

Variables

This section is empty.

Functions

func FileExists

func FileExists(filename string) (bool, error)

func MethodNotAllowedHandler

func MethodNotAllowedHandler() http.Handler

MethodNotAllowedHandler returns a simple request handler that replies to each request with a “405 method not allowed” reply.

Types

type Configuration

type Configuration struct {
	Address string
}

Configuration for a http server.

type Context

type Context struct {
	Validator *validator.Validate
	LastError error
	// contains filtered or unexported fields
}

Context wraps http.Request and http.ResponseWriter. Returned set to true if response was written to then don't execute other handler.

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request) *Context

NewContext create a new context.

func (*Context) Cookies

func (c *Context) Cookies() []*http.Cookie

Cookies return all cookies.

func (*Context) FormParams

func (c *Context) FormParams() (url.Values, error)

FormParams return the parsed form data

func (*Context) FormValue

func (c *Context) FormValue(name string) string

FormValue returns the first value for the named component of the query.

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get a value for a key.

func (*Context) GetCookie

func (c *Context) GetCookie(key string) (*http.Cookie, error)

GetCookie Get cookie from request by a given key.

func (*Context) GetHeader

func (c *Context) GetHeader(key string) string

GetHeader Get header from request by a given key.

func (*Context) JSONBody

func (c *Context) JSONBody(v interface{}) error

JSONBody parses the JSON request body.

func (*Context) Redirect

func (c *Context) Redirect(status int, url string) error

Redirect does redirection to localurl with http header status code.

func (*Context) Request

func (c *Context) Request() *http.Request

Request return the request.

func (*Context) Reset

func (c *Context) Reset(w http.ResponseWriter, r *http.Request)

Reset the context.

func (*Context) Response

func (c *Context) Response() http.ResponseWriter

Response return the responseWriter

func (*Context) ServeJSON

func (c *Context) ServeJSON(v interface{}) error

ServeJSON sends a JSON response.

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set a kev/value on context.

func (*Context) SetCookie

func (c *Context) SetCookie(name string, value string)

SetCookie Set cookie for response.

func (*Context) SetHeader

func (c *Context) SetHeader(key, val string)

SetHeader Set header for response.

func (*Context) SetRequest

func (c *Context) SetRequest(r *http.Request)

SetRequest set the r as the new request.

func (*Context) Validate

func (c *Context) Validate(val interface{}) error

Validate the parameters.

func (*Context) WriteHeader

func (c *Context) WriteHeader(code int) error

WriteHeader sends an HTTP response header with status code.

type Entrypoint

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

Entrypoint represents a http server.

func NewEntrypoint

func NewEntrypoint(conf *Configuration, tlsConf *TLSConfiguration) *Entrypoint

NewEntrypoint creates a new Entrypoint.

func (*Entrypoint) AttachMiddleware

func (ep *Entrypoint) AttachMiddleware(handler negroni.Handler)

AttachMiddleware attach a new middleware on entrypoint.

func (*Entrypoint) Run

func (ep *Entrypoint) Run()

Run until stop channel emits a value.

func (*Entrypoint) Start

func (ep *Entrypoint) Start(router http.Handler) error

Start the entrypoint.

func (*Entrypoint) Stop

func (ep *Entrypoint) Stop()

Stop the http server.

func (*Entrypoint) Wait

func (ep *Entrypoint) Wait()

Wait until stop channel emits a value.

type FilterFunc

type FilterFunc func(*Context) bool

FilterFunc defines a filter function which is invoked before the controller handler is executed.

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc defines a handler function to handle http request.

type Router

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

Router register routes to be matched and dispatched to a handler.

func NewRouter

func NewRouter() *Router

NewRouter returns a router.

func (*Router) Get

func (rt *Router) Get(pattern string, handler HandlerFunc, filters ...FilterFunc)

Get adds a route path access via GET method.

func (*Router) Handler

func (rt *Router) Handler() http.Handler

Handler returns a http.Handler.

func (*Router) Post

func (rt *Router) Post(pattern string, handler HandlerFunc, filters ...FilterFunc)

Post adds a route path access via POST method.

func (*Router) SetErrorHandler

func (rt *Router) SetErrorHandler(h func(*Context))

SetErrorHandler attach a global error handler on router.

type TLSConfiguration

type TLSConfiguration struct {
	Key  string
	Cert string
}

TLSConfiguration is the configuration for a https server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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