Documentation
¶
Index ¶
- Constants
- Variables
- func FormResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
- func IP(req *http.Request) string
- func JSONResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
- func ListenAndServeWebsocket(addr, path string, handler netutil.ConnHandler, async bool) error
- func NewHandler(method string, h http.Handler) http.Handler
- func NewHandlerFunc(method string, h http.HandlerFunc) http.Handler
- func ParseBool(r *http.Request, key string, dft bool) (bool, error)
- func ParseFloat32(r *http.Request, key string, dft float32) (float32, error)
- func ParseFloat64(r *http.Request, key string, dft float64) (float64, error)
- func ParseInt(r *http.Request, key string, dft int) (int, error)
- func ParseInt16(r *http.Request, key string, dft int16) (int16, error)
- func ParseInt32(r *http.Request, key string, dft int32) (int32, error)
- func ParseInt64(r *http.Request, key string, dft int64) (int64, error)
- func ParseInt8(r *http.Request, key string, dft int8) (int8, error)
- func ParseIntegers(r *http.Request, key string) ([]int64, error)
- func ParseJSON(r *http.Request, key string, ptr interface{}) error
- func ParseRequiredBool(r *http.Request, key string) (bool, error)
- func ParseRequiredFloat32(r *http.Request, key string) (float32, error)
- func ParseRequiredFloat64(r *http.Request, key string) (float64, error)
- func ParseRequiredInt(r *http.Request, key string) (int, error)
- func ParseRequiredInt16(r *http.Request, key string) (int16, error)
- func ParseRequiredInt32(r *http.Request, key string) (int32, error)
- func ParseRequiredInt64(r *http.Request, key string) (int64, error)
- func ParseRequiredInt8(r *http.Request, key string) (int8, error)
- func ParseRequiredString(r *http.Request, key string) (string, error)
- func ParseRequiredUint(r *http.Request, key string) (uint, error)
- func ParseRequiredUint16(r *http.Request, key string) (uint16, error)
- func ParseRequiredUint32(r *http.Request, key string) (uint32, error)
- func ParseRequiredUint64(r *http.Request, key string) (uint64, error)
- func ParseRequiredUint8(r *http.Request, key string) (uint8, error)
- func ParseString(r *http.Request, key string, dft string) string
- func ParseUint(r *http.Request, key string, dft uint) (uint, error)
- func ParseUint16(r *http.Request, key string, dft uint16) (uint16, error)
- func ParseUint32(r *http.Request, key string, dft uint32) (uint32, error)
- func ParseUint64(r *http.Request, key string, dft uint64) (uint64, error)
- func ParseUint8(r *http.Request, key string, dft uint8) (uint8, error)
- func PingHandler(w http.ResponseWriter, r *http.Request)
- func PostFormJSON(httpc *http.Client, url_ string, data url.Values, res interface{}) error
- func Response(w http.ResponseWriter, body interface{}, options ...ResponseOptions) error
- func TextResponse(w http.ResponseWriter, value string, options ...ResponseOptions) error
- func VerifySign(signer Signer, key, keyField, signField string, args url.Values) error
- func XMLResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
- type Config
- type FormMarshaler
- type HTTPServer
- func (httpd *HTTPServer) Handle(pattern string, handler http.Handler, middlewares ...Middleware)
- func (httpd *HTTPServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request), ...)
- func (httpd *HTTPServer) JSONResponse(w http.ResponseWriter, r *http.Request, data interface{}, ...)
- func (httpd *HTTPServer) ListenAndServe(async bool) error
- func (httpd *HTTPServer) NumHandling() int64
- func (httpd *HTTPServer) Shutdown(ctx context.Context) error
- type HandlerConnect
- type HandlerDelete
- type HandlerGet
- type HandlerHead
- type HandlerMatcher
- type HandlerOptions
- type HandlerPatch
- type HandlerPost
- type HandlerPut
- type HandlerTrace
- type MarshalFunc
- type Middleware
- type MiddlewareFunc
- type Pager
- type ResponseOptions
- type Result
- type ServeMux
- type Signer
Constants ¶
View Source
const ( Unused = 0 MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationFormCharsetUTF8 = MIMEApplicationForm + "; " + charsetUTF8 MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
View Source
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" HeaderAllow = "Allow" HeaderAuthorization = "Authorization" HeaderContentDisposition = "Content-Disposition" HeaderContentEncoding = "Content-Encoding" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderCookie = "Cookie" HeaderSetCookie = "Set-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderServer = "Server" HeaderOrigin = "Origin" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-Options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXCSRFToken = "X-CSRF-Token" )
Variables ¶
View Source
var ( ErrUnableToMarshalForm = errors.New("unable to marshal form") ErrSign = errors.New("failed to verify sign") )
View Source
var ( ErrInvalidInteger = errors.New("invalid integer") ErrInvalidFloatNumber = errors.New("invalid float number") ErrInvalidBoolean = errors.New("invalid boolean") )
View Source
var (
ErrMissingRequiredArgument = errors.New("missing required argument")
)
Functions ¶
func FormResponse ¶
func FormResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
func JSONResponse ¶
func JSONResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
func ListenAndServeWebsocket ¶
func ListenAndServeWebsocket(addr, path string, handler netutil.ConnHandler, async bool) error
ListenAndServeWebsocket starts a http server and registers a websocket handler
func NewHandlerFunc ¶
func NewHandlerFunc(method string, h http.HandlerFunc) http.Handler
func PingHandler ¶
func PingHandler(w http.ResponseWriter, r *http.Request)
func PostFormJSON ¶
func Response ¶
func Response(w http.ResponseWriter, body interface{}, options ...ResponseOptions) error
func TextResponse ¶
func TextResponse(w http.ResponseWriter, value string, options ...ResponseOptions) error
func VerifySign ¶
func XMLResponse ¶
func XMLResponse(w http.ResponseWriter, value interface{}, options ...ResponseOptions) error
Types ¶
type FormMarshaler ¶
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
HTTPServer ...
func NewHTTPServer ¶
func NewHTTPServer(cfg Config) *HTTPServer
func (*HTTPServer) Handle ¶
func (httpd *HTTPServer) Handle(pattern string, handler http.Handler, middlewares ...Middleware)
func (*HTTPServer) HandleFunc ¶
func (httpd *HTTPServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request), middlewares ...Middleware)
func (*HTTPServer) JSONResponse ¶
func (httpd *HTTPServer) JSONResponse(w http.ResponseWriter, r *http.Request, data interface{}, options ...ResponseOptions)
func (*HTTPServer) ListenAndServe ¶
func (httpd *HTTPServer) ListenAndServe(async bool) error
func (*HTTPServer) NumHandling ¶
func (httpd *HTTPServer) NumHandling() int64
type HandlerConnect ¶
type HandlerConnect struct{}
type HandlerDelete ¶
type HandlerDelete struct{}
type HandlerGet ¶
type HandlerGet struct{}
type HandlerHead ¶
type HandlerHead struct{}
type HandlerMatcher ¶
type HandlerOptions ¶
type HandlerOptions struct{}
type HandlerPatch ¶
type HandlerPatch struct{}
type HandlerPost ¶
type HandlerPost struct{}
type HandlerPut ¶
type HandlerPut struct{}
type HandlerTrace ¶
type HandlerTrace struct{}
type MarshalFunc ¶
type MiddlewareFunc ¶
MiddlewareFunc implements Middleware interface
type ResponseOptions ¶
type ResponseOptions func(opts *responseOptions)
func WithAcceptType ¶
func WithAcceptType(acceptType string) ResponseOptions
func WithContentType ¶
func WithContentType(contentType string) ResponseOptions
func WithStatus ¶
func WithStatus(status int) ResponseOptions
type ServeMux ¶
func NewServeMux ¶
func NewServeMux() *ServeMux
Click to show internal directories.
Click to hide internal directories.