web

package
v0.0.0-...-10f03cb Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

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, migration string, daoType dao.DBType, statisticsDuration time.Duration) (*negroni.Negroni, error)

BuildWebServer constructs a new web server with the right DAO and tasks 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 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

func URLParamAsString

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

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

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(controller *TaskController) *Router

NewRouter creates a new router instance

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)

type TaskController

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

TaskController is a controller for tasks resource

func NewTaskController

func NewTaskController(taskDAO dao.TaskDAO) *TaskController

NewTaskController creates a new task controller to manage tasks

func (*TaskController) Create

func (sh *TaskController) Create(w http.ResponseWriter, r *http.Request)

Create create an entity

func (*TaskController) Delete

func (sh *TaskController) Delete(w http.ResponseWriter, r *http.Request)

Delete delete an entity by id

func (*TaskController) Get

Get retrieve an entity by id

func (*TaskController) GetAll

func (sh *TaskController) 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 (*TaskController) Update

func (sh *TaskController) Update(w http.ResponseWriter, r *http.Request)

Update update an entity by id

Jump to

Keyboard shortcuts

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