Documentation ¶
Index ¶
- Constants
- Variables
- func ContextSetterMiddleware(next http.Handler) http.Handler
- func GZIPCompressMiddleware(next http.Handler) http.Handler
- func GetRequestID(r *http.Request) string
- func InternalServerError(w http.ResponseWriter, err error)
- func MakeRequestID() string
- func NewCORSMiddleware(options cors.Options) func(next http.Handler) http.Handler
- func WriteJson(w http.ResponseWriter, code int, data interface{})
- func WriteString(w http.ResponseWriter, code int, text string)
- type ContextKey
- type HyperMux
Constants ¶
const ( MethodGet = "GET" MethodPost = "POST" MethodPut = "PUT" MethodDelete = "DELETE" MethodHead = "HEAD" MethodOptions = "OPTIONS" MethodPatch = "PATCH" )
const (
CharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
Variables ¶
var ( DefaultCORSOption = cors.Options{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{MethodPost, MethodGet, MethodDelete, MethodPut}, AllowedHeaders: []string{"Authorization", "Content-Type", "Content-Length", "Content-Encoding", "Accept", "Accept-Encoding"}, ExposedHeaders: []string{"*", "Authorization"}, MaxAge: 300, AllowCredentials: true, OptionsPassthrough: false, Debug: true, } Cors *cors.Cors )
Functions ¶
func ContextSetterMiddleware ¶
ContextSetterMiddleware is a middleware function that will ensure the request context existance.
func GZIPCompressMiddleware ¶ added in v1.1.0
GZIPCompressMiddleware is a wrapper for easy GZIP Content Handling.
func GetRequestID ¶
GetRequestID will retrieve the RequestID value from context if ContextSetterMiddleware middleware is used. If ContextSetterMiddleware is not used, it will return empty string
func InternalServerError ¶
func InternalServerError(w http.ResponseWriter, err error)
InternalServerError writes error message to the http.ResponseWriter
func MakeRequestID ¶
func MakeRequestID() string
func NewCORSMiddleware ¶
NewCORSMiddleware will create CORS middleware to be used in your web app this middleware will handle the OPTIONS method automatically.
func WriteJson ¶
func WriteJson(w http.ResponseWriter, code int, data interface{})
WriteJson simply writes a JSON to the http.ResponseWriter of type application/json if the marshaled data is not marshallable to json, it write an internal server error.
func WriteString ¶
func WriteString(w http.ResponseWriter, code int, text string)
WriteString simply write to the http.ResponseWriter a text of type text/plain
Types ¶
type HyperMux ¶
type HyperMux struct {
// contains filtered or unexported fields
}
HyperMux holds all the end-point routings and middlewares.
func (*HyperMux) AddRoute ¶
func (m *HyperMux) AddRoute(pattern, method string, hFunc http.HandlerFunc)
AddRoute add a routing to a HTTP resource