Documentation ¶
Overview ¶
Package webservice implements an API server that works with HTTP requests in JSON and form-request format.
Index ¶
- Constants
- func Handler(f ContextFunc) http.HandlerFunc
- type Context
- func (c *Context) Decode(obj interface{}) error
- func (c *Context) EarlyResponse() error
- func (c *Context) Empty() 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) Param(name string) string
- func (c *Context) Query() url.Values
- func (c *Context) Raw() ([]byte, error)
- 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) Text(body interface{}) error
- func (c *Context) Writer(ct string) (WebWriter, error)
- type ContextFunc
- type EncoderFunc
- type HTTPError
- type HandlerFunc
- type JSONEncoder
- type MsgpackEncoder
- type ResponseEncoder
- type Router
- type Server
- type WebWriter
Constants ¶
View Source
const DefaultMaxDecodeSize = 1 << 19 // 512kB
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 { MaxDecodeSize int64 Encoder ResponseEncoder 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 JSONEncoder ¶
type JSONEncoder struct{}
func (JSONEncoder) ContentType ¶
func (JSONEncoder) ContentType() string
func (JSONEncoder) Encode ¶
func (JSONEncoder) Encode(w io.Writer, obj interface{}) error
type MsgpackEncoder ¶
type MsgpackEncoder struct{}
func (MsgpackEncoder) ContentType ¶
func (MsgpackEncoder) ContentType() string
func (MsgpackEncoder) Encode ¶
func (MsgpackEncoder) Encode(w io.Writer, obj interface{}) error
type ResponseEncoder ¶
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.