Documentation ¶
Index ¶
- Constants
- func GetJSONContent(v interface{}, r *http.Request) error
- func InitLog(logLevel, formatter string) 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)
- func TimeTrack(start time.Time, name string)
- type Statistics
Constants ¶
View Source
const ( // LogStashFormatter is constant used to format logs as logstash format LogStashFormatter = "logstash" // TextFormatter is constant used to format logs as simple text format TextFormatter = "text" )
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 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 Statistics ¶
type Statistics struct {
// contains filtered or unexported fields
}
Statistics is the worker to persist the request statistics
func NewStatistics ¶
func NewStatistics(loggingPeriod time.Duration) *Statistics
NewStatistics creates a new statistics structure and launches its worker routine
func (*Statistics) PlusOne ¶
func (sw *Statistics) PlusOne()
PlusOne is used to add one to the counter
Click to show internal directories.
Click to hide internal directories.