web

package
v0.0.0-...-3a230e9 Latest Latest
Warning

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

Go to latest
Published: May 13, 2018 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ResponseHeaderContentTypeKey is the key used for response content type
	ResponseHeaderContentTypeKey = "Content-Type"
	// ResponseHeaderContentTypeJSONUTF8 is the key used for UTF8 JSON response
	ResponseHeaderContentTypeJSONUTF8 = "application/json; charset=UTF-8"
)

Variables

This section is empty.

Functions

func BuildWebServer

func BuildWebServer(db string, daoType dao.DBType, statisticsDuration time.Duration) (*negroni.Negroni, error)

BuildWebServer constructs a new web server with the right DAO and spirits handler

func GetJSONContent

func GetJSONContent(v interface{}, r *http.Request) error

GetJSONContent returns the JSON content of a request

func NotFoundHandler

func NotFoundHandler() http.HandlerFunc

NotFoundHandler return a JSON implementation of the not found handler

func ParamAsString

func ParamAsString(name string, r *http.Request) string

ParamAsString returns an URL parameter /{name} as a string

func QueryParamAsString

func QueryParamAsString(name string, r *http.Request) string

QueryParamAsString Param Return a url param as an int

func SendJSONError

func SendJSONError(w http.ResponseWriter, error string, code int)

SendJSONError sends error with a custom message and error code

func SendJSONNotFound

func SendJSONNotFound(w http.ResponseWriter)

SendJSONNotFound produces a http.StatusNotFound response with the following JSON, '{"Error":"Resource not found"}'

func SendJSONOk

func SendJSONOk(w http.ResponseWriter, d interface{})

SendJSONOk outputs a JSON with http.StatusOK code

func SendJSONWithHTTPCode

func SendJSONWithHTTPCode(w http.ResponseWriter, d interface{}, code int)

SendJSONWithHTTPCode outputs JSON with an HTTP code

Types

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route is a structure of Route

type Router

type Router struct {
	*mux.Router
}

Router is the struct use for routing

func NewRouter

func NewRouter(handler *SpiritController) *Router

NewRouter creates a new router instance

type SpiritController

type SpiritController struct {
	Routes []Route
	Prefix string
	// contains filtered or unexported fields
}

SpiritController is a handler of spirits

func NewSpiritController

func NewSpiritController(spiritDAO dao.SpiritDAO) *SpiritController

NewSpiritController creates a new spirit handler to manage spirits

func (*SpiritController) Create

func (sc *SpiritController) Create(w http.ResponseWriter, r *http.Request)

Create create an entity

func (*SpiritController) Delete

func (sc *SpiritController) Delete(w http.ResponseWriter, r *http.Request)

Delete delete an entity by id

func (*SpiritController) Get

Get retrieve an entity by id

func (*SpiritController) GetAll

func (sc *SpiritController) GetAll(w http.ResponseWriter, r *http.Request)

GetAll retrieve all entities with optional paging of items (start / end are item counts 50 to 100 for example)

func (*SpiritController) Update

func (sc *SpiritController) Update(w http.ResponseWriter, r *http.Request)

Update update an entity by id

type StatisticsMiddleware

type StatisticsMiddleware struct {
	Stat *statistics.Statistics
}

StatisticsMiddleware is the middleware to record request statistics

func NewStatisticsMiddleware

func NewStatisticsMiddleware(duration time.Duration) *StatisticsMiddleware

NewStatisticsMiddleware creates a new statistics middleware

func (*StatisticsMiddleware) ServeHTTP

func (sm *StatisticsMiddleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Jump to

Keyboard shortcuts

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