Documentation
¶
Index ¶
- Variables
- type Config
- type Context
- func (ctx *Context) Body() []byte
- func (ctx *Context) Context() *Context
- func (ctx *Context) GetRequest() *http.Request
- func (ctx *Context) GetResponseWriter() ResponseWriter
- func (ctx *Context) Redirect(addr string, httpstatus ...int)
- func (ctx *Context) Reply(httpstatus int, obj ...interface{}) (err error)
- func (ctx *Context) ResponseHeader() http.Header
- func (ctx *Context) SetCookies(cookies ...*http.Cookie)
- func (ctx *Context) StatusCode() int
- func (ctx *Context) Write(httpstatus int, data []byte) (err error)
- type Controller
- type HTTPHandler
- type Host
- func (host *Host) AddEndpoint(method string, path string, handler HTTPHandler, middlewares ...Middleware) (err error)
- func (host *Host) Errors() []error
- func (host *Host) Group(basepath string, register func(), middlewares ...Middleware)
- func (host *Host) Register(basepath string, controller Controller, middlewares ...Middleware) (err error)
- func (host *Host) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (host *Host) Use(middlewares ...Middleware) *Host
- type LogService
- type Middleware
- type Reply
- type Replyable
- type ResponseWriter
- type Serializer
- type Validator
Constants ¶
This section is empty.
Variables ¶
var (
Serializers = map[string]Serializer{
"application/x-www-form-urlencoded": &formSerializer{},
"application/json": &jsonSerializer{},
"application/xml": &xmlSerializer{},
"": &jsonSerializer{},
}
)
JSONSerializer JSON Serializer
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
//UseLowerLetter Use lower letter in path
UseLowerLetter bool
//AliasTagName Replace the system rule name with the provided name, default is "api"
AliasTagName string
//HTTPMethodTagName Specify the specific method for the endpoint, default is "options"
HTTPMethodTagName string
//CustomisedPlaceholder Used to specify where the parameters should be in the URL. The specified string will quoted by {}.
//E.G.: param -> {param}
CustomisedPlaceholder string
//AutoReport This option will display route table after successful registration
DisableAutoReport bool
}
Config Configuration
type Context ¶
type Context struct {
Deserializer Serializer
Serializer Serializer
BeforeReading func([]byte) []byte
BeforeWriting func(int, []byte) []byte
// contains filtered or unexported fields
}
Context HTTP Request Context
func (*Context) GetRequest ¶
GetRequest Get Request from Context
func (*Context) GetResponseWriter ¶
func (ctx *Context) GetResponseWriter() ResponseWriter
GetResponseWriter Get ResponseWriter as io.Writer to support stream write
func (*Context) Reply ¶
Reply Reply to client with any data which can be marshaled into bytes if not bytes or string
func (*Context) ResponseHeader ¶
ResponseHeader Response Header
func (*Context) SetCookies ¶
SetCookies Set cookies
type Controller ¶
type Controller interface {
Redirect(string, ...int)
SetCookies(...*http.Cookie)
Reply(int, ...interface{}) error
Write(int, []byte) error
ResponseHeader() http.Header
Context() *Context
}
Controller Controller statement
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host Service for HTTP
func NewHost ¶
func NewHost(conf Config, middlewares ...Middleware) (host *Host)
NewHost Create a new service host
func (*Host) AddEndpoint ¶
func (host *Host) AddEndpoint(method string, path string, handler HTTPHandler, middlewares ...Middleware) (err error)
AddEndpoint Register the endpoint with the host
func (*Host) Group ¶
func (host *Host) Group(basepath string, register func(), middlewares ...Middleware)
Group Set prefix to endpoints
func (*Host) Register ¶
func (host *Host) Register(basepath string, controller Controller, middlewares ...Middleware) (err error)
Register Register the controller with the host
func (*Host) ServeHTTP ¶
func (host *Host) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP service http request
func (*Host) Use ¶
func (host *Host) Use(middlewares ...Middleware) *Host
Use Add middlewares into host
type LogService ¶
type LogService interface {
//Log with [datetime] prefix
Log(tpl string, args ...interface{})
//Write only text
Write(tpl string, args ...interface{})
//Stop exit
Stop()
}
LogService Log service
type Middleware ¶
type Middleware interface {
Invoke(ctx *Context, next HTTPHandler)
}
Middleware Middleware
type Reply ¶
type Reply struct {
Status int
Body interface{}
}
Reply Default implementation of Response
type Replyable ¶
type Replyable interface {
StatusCode() int
Data() interface{}
}
Replyable Replyable for request reply
type ResponseWriter ¶
type ResponseWriter interface {
Write(p []byte) (int, error)
Header() http.Header
WriteHeader(statusCode int)
}
ResponseWriter is a alternative for ResponseWriter Request