Documentation ¶
Overview ¶
Package webservice implements an API server that works with HTTP requests in JSON and form-request format.
Index ¶
- func Handler(f ContextFunc) http.HandlerFunc
- type Context
- func (c *Context) Decode(obj interface{}) error
- func (c *Context) EarlyResponse() error
- func (c *Context) Error(code int, err string, message interface{}) error
- func (c *Context) File(name string) (f multipart.File, fh *multipart.FileHeader, err error)
- func (c *Context) Query() url.Values
- func (c *Context) RealIP() string
- func (c *Context) Respond(body interface{}) error
- func (c *Context) ServeFile(fname, ct string) error
- func (c *Context) StandardError(err error) error
- func (c *Context) StartResponse()
- func (c *Context) Vars() map[string]string
- func (c *Context) Writer(ct string) (WebWriter, error)
- type ContextFunc
- type HTTPError
- type HandlerFunc
- type Server
- type WebWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(f ContextFunc) http.HandlerFunc
Handler turns an ContextFunc into a HandlerFunc.
Types ¶
type Context ¶
type Context struct { Wr http.ResponseWriter Req *http.Request Code int // contains filtered or unexported fields }
Context contains context for JSON and form requests.
func (*Context) File ¶
func (*Context) RealIP ¶
RealIP returns the actual IP of the remote caller. It assumes the webserver is not exposed to an untrusted network directly (i.e., X-Forwarded-For cannot be spoofed.)
type HTTPError ¶
type HTTPError struct { Code int `json:"code"` Const string `json:"error"` Message string `json:"message,omitempty"` }
HTTPError is a generic error with an associated HTTP status code.
type HandlerFunc ¶
type HandlerFunc = http.HandlerFunc
type Server ¶
Server is a convenience wrapper with a router, HTTP/1 and HTTP/2 server implementation.
Click to show internal directories.
Click to hide internal directories.