Documentation
¶
Index ¶
- Constants
- func BuildWebServer(db string, daoType dao.DBType, statisticsDuration time.Duration) (*negroni.Negroni, error)
- func GetJSONContent(v interface{}, r *http.Request) error
- func NotFoundHandler() http.HandlerFunc
- func ParamAsString(name string, r *http.Request) string
- func SendJSONError(w http.ResponseWriter, error string, code int)
- func SendJSONNotFound(w http.ResponseWriter)
- func SendJSONOk(w http.ResponseWriter, d interface{})
- func SendJSONWithHTTPCode(w http.ResponseWriter, d interface{}, code int)
- type Route
- type Router
- type SpiritController
- func (sh *SpiritController) Create(w http.ResponseWriter, r *http.Request)
- func (sh *SpiritController) Delete(w http.ResponseWriter, r *http.Request)
- func (sh *SpiritController) Get(w http.ResponseWriter, r *http.Request)
- func (sh *SpiritController) GetAll(w http.ResponseWriter, r *http.Request)
- func (sh *SpiritController) Update(w http.ResponseWriter, r *http.Request)
- type StatisticsMiddleware
Constants ¶
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 ¶
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 ¶
ParamAsString returns an URL parameter /{name} as a string
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 ¶
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 (sh *SpiritController) Create(w http.ResponseWriter, r *http.Request)
Create create an entity
func (*SpiritController) Delete ¶
func (sh *SpiritController) Delete(w http.ResponseWriter, r *http.Request)
Delete delete an entity by id
func (*SpiritController) Get ¶
func (sh *SpiritController) Get(w http.ResponseWriter, r *http.Request)
Get retrieve an entity by id
func (*SpiritController) GetAll ¶
func (sh *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 (sh *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)