utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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

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

GetJSONContent returns the JSON content of a request

func InitLog

func InitLog(logLevel, formatter string) error

InitLog initializes the logrus logger

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 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 TimeTrack

func TimeTrack(start time.Time, name string)

TimeTrack is used to log execution times for functions

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

Jump to

Keyboard shortcuts

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