Documentation ¶
Index ¶
- Constants
- Variables
- func IsMapErrorHandled(w http.ResponseWriter, req *http.Request, err error, status *int) (handled bool)
- func Render(w http.ResponseWriter, data interface{}, status *int)
- type Context
- func (c *Context) AbsURL() string
- func (c *Context) Bind(value interface{}) error
- func (c *Context) GetFormBool(name string) bool
- func (c *Context) GetFormFloat(name string) float64
- func (c *Context) GetFormInt(name string) int64
- func (c *Context) IsTLS() bool
- func (c *Context) MapBad(code, format string, args ...interface{}) *Map
- func (c *Context) MapUnhandled(code, format string, args ...interface{}) *Map
- func (c *Context) RealIp() string
- func (c *Context) Scheme() string
- type Doc
- type DocParamItem
- type Empty
- type HandlerFunc
- type M
- type Map
- func MapBad(code, format string, args ...interface{}) *Map
- func MapForbidden(code, format string, args ...interface{}) *Map
- func MapStatus(status int) *Map
- func MapUnauthorized(code, format string, args ...interface{}) *Map
- func MapUnhandled(code, format string, args ...interface{}) *Map
- func NewMap(maps ...M) *Map
- func Redirect(status int, redirectTo string) *Map
- func (m *Map) Basic(code, format string, args ...interface{}) *Map
- func (m *Map) Del(key string) *Map
- func (m *Map) Error() string
- func (m Map) MarshalBinary() ([]byte, error)
- func (m Map) MarshalJSON() ([]byte, error)
- func (m *Map) Merge(maps ...M) *Map
- func (m *Map) PopStatus(status *int) bool
- func (m *Map) Redirect(status *int, redirectTo *string) bool
- func (m *Map) Set(key string, val interface{}) *Map
- func (m *Map) SetCode(code string) *Map
- func (m *Map) SetData(data interface{}) *Map
- func (m *Map) SetEx(err error) *Map
- func (m *Map) SetMessage(format string, args ...interface{}) *Map
- func (m *Map) SetStatus(status int) *Map
- func (m Map) String() string
- type Matched
- type Mux
- func (m *Mux) Handle(method, pattern string, handler HandlerFunc)
- func (m *Mux) HandleService(pathPrefix string, svc interface{})
- func (m *Mux) HandleServices(ss ...interface{})
- func (m *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (m *Mux) SetBasicAuth(auth M)
- func (m *Mux) Start(addr string) error
- func (m *Mux) StartWith(s Server) error
- type Node
- type Options
- type Params
- type Printer
- type Server
Constants ¶
const ( MimeHTML = "text/html" MimeJSON = "application/json" MimeFormUrlencoded = "application/x-www-form-urlencoded" MimeFormData = "multipart/form-data" HeaderContentType = "Content-Type" )
const ( HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Scheme" )
Variables ¶
var DocGomd = &embed.File{
FileName: "doc.gomd",
FileModTime: 1608536003,
FileSize: 1307,
Data: `
H4sIAAAAAAAC/2yU307jRhTG7+cpjkwuIIrjq95YaiVUQLQSJAq5b9xkCG5jO7UnCq1tiaQgVZA0iJIW
WokS7WoXaaU1aFf8383LZMbhal9hNZ4QTDa+mTNnfvPpzDlf4royKMmyRX6tYhU047eibSg/asWfsVlS
akSvOErZctILVjGpgOz7CM3MgOtCelUzMPg+4gJ1nWxAegE7RVuvEt0y+QH6JuIeGWyWQFyfgWFwxS6a
4ZsgbN4gVOBYViMb4PuFOMD+vmHvulyIHQas1ViybGPYO6PtLj1ofb+WWWVnPXrfQahQKBC8SdAKJhtW
SUUA2cxaHqFlrJWwzfffWibBJpHz/JkIAICLqTwASatWK3pR44Urm3K9XpfXLduQa3YFm0WrhEvS+MaS
XsEqSEatQvSqZhMlIksa0QTDq5qi+pNjmRIvE8X69Z1ZrZGsZmuGM9EZ2mmy7jlCHoiI7rfD1+fgQXhx
R0/2wAPa33no3YEHrNMZ9qOjl7eDj3t06x485IEqy7IMo1UsKkykwYuKsTWzjMWcvPhkQex4x8Y7fR3S
OfxLTbcxnyY7Clx3NNkR/twEo+TipmZUK0Imboa4Lyb6EuWSSfGqWd7luWQymjTvJYqc5QHPczLq7Jjm
xDSax2P6C0/2D+l/J6x7ztpvZ9kf+3T3/7nnCpka4YVN0RF1L9q2ZTvTBR8Oj4dB8CT4FXIRgMTdJalS
dj43v/LDYi6XyUkpUBRBD+5ehKcNjhlOWVIl4QVxJqVAfIpCO83h1u/CBxyOzKiCC/FPUR6Ot+nu6aDf
Y43g032LvmoOrvcG17dxVfbPpaia7lwNPvwlkuG/24IRdyObSxNHdL89UeAweM+O/pRSCMBPofGElvP5
bLh7ybYa4WmDHrTiLx1NLPolPxkz4RCN1JwUJAxQv378P3lMg++rcdhMQcLhXCLyBa+Vw3xcahQ5E76L
hZO2+BwAAP//RcmzlRsFAAA=
`,
}
var DocHtml = &embed.File{
FileName: "doc.html",
FileModTime: 1608541774,
FileSize: 1202,
Data: `
H4sIAAAAAAAC/6RUS3PTMBC+51cs4gIzlZ122rR17EyH1xUO4cBRlraxsCwJaROnzeS/M86LxBRaBl28
1rf6HppZ5a8+fH4//fblI1TUmMkg7z5ghJ0V7LFi3QYKNRkAAOQNkgBZiRCRCvZ1+onfsGPIigYLttDY
eheIgXSW0FLBWq2oKhQutES++TkDbTVpYXiUwmBxngz3VKTJ4GS1gmTaVbBe5+l2b4sbbWsIaAoW6cFg
rBCJQRXwvmAVkY9Zmkplk+9RodGLkFik1PomnWmq5iVvRKiVay2XMd5dJsNfyhu+bd2t5NBZOvUAqwPQ
rdItedSP2s4yKF1QGHjpluOTnkbbbdoMLoZD30fFco/e3jyBhpm2GQxBzMmdYl4otRG+vOofu3eWOl+Y
wfnlMbgeHMq7BpUW8ObIwPXo2i/f9iL+Nf+Jj/PffKyfEu4R+oAgncIe83GEiz6vdMaFDF6PRqPxCyRK
42T9Y+4Iwb9U5s9sJEqDQOrsmYaqJ9W6oHgZUNQZ1IieC2NOY7WVJuTRC4kZWNcG4cf/fSnPmEShgMK/
XH4pZD0Lbm4V30viFd6i7Kvm6W6U8nT7fOSd8mSQi0BaGgRpRIwFOzHGNjP/rrPYjfyutePYHU43T9TP
AAAA///3I0uusgQAAA==
`,
}
var DocIndexGohtml = &embed.File{
FileName: "doc_index.gohtml",
FileModTime: 1608549553,
FileSize: 1592,
Data: `
H4sIAAAAAAAC/7SVTVPbPBDH7/kU+/i5tDMoDhkIYOwMM305daY90EOPsrREqmXJlTYvwOS7dxRjiN1Q
4NC9SNF/s7//aux1/t/Hrx+uf3z7BIpqMx/lcQHD7aJI7lQSD5DL+QgAIK+ROAjFfUAqku/Xn9l5si9Z
XmORrDSuG+cpAeEsoaUiWWtJqpC40gLZ7scRaKtJc8OC4AaL4/GkK0WaDM7v72F8HXew3eZpe9bqRtsK
PJoiCXRrMChESkB5vCkSRdSELE2FtOOfQaLRKz+2SKlt6nShSS1LVnNfSbe2TIRwdTKePJF39dp9jPFj
ZunkLdw/CjFKt2FB32m7yKB0XqJnpdtc9nJqbdtuM5hOJs1Q5ZtOvTg/oPqFthlMgC/J9bWGS7kDn5wO
/3bjLEVfmMHxyb64HT1ur2qUmsO7PQNns7Nm837Q4l/77/k4/sPH9hB4ULDxCMJJHFTeb2E6rCuccT6D
/2ez2eUrEKVxovq1dITQvBbzfDXipUEgefRCghqg1s5LVnrkVQYVYsO4Mf221koTstBwgRlYt/a8ufxn
l9K5RC6B/Ftuv+SiWni3tJJ1TDzFCxSvwUoDc5B0kBdfvNi4r7l5+wN9ECRhDnwA60xf7KIPItwQkyic
56SdjW4svhGXKbdC/wx0tosXoEsr0RvdJ++GU/ownfK0nch5hM9Hec21BWF4CEXSM9ZNNTUdDFM1fVCk
eRp2MeWLtlWAbQeMcp7G+nF9wKXtd+J3AAAA///SAP7WOAYAAA==
`,
}
Functions ¶
func IsMapErrorHandled ¶
func Render ¶
func Render(w http.ResponseWriter, data interface{}, status *int)
Types ¶
type Context ¶
func (*Context) GetFormBool ¶
func (*Context) GetFormFloat ¶
func (*Context) GetFormInt ¶
func (*Context) MapUnhandled ¶
type Doc ¶
type DocParamItem ¶
type HandlerFunc ¶
type Map ¶
type Map struct {
M
}
func (Map) MarshalBinary ¶
func (Map) MarshalJSON ¶
func (*Map) SetMessage ¶
type Matched ¶
type Matched struct { // Either a Node pointer when matched or nil Node *Node // Either a map contained matched values or empty map. Params map[string]string // If FixedPathRedirect enabled, it may returns a redirect path, // otherwise a empty string. FPR string // If TrailingSlashRedirect enabled, it may returns a redirect path, // otherwise a empty string. TSR string }
Matched is a result returned by trie.Match.
type Mux ¶
type Mux struct { Printer // contains filtered or unexported fields }
Mux is a tire base HTTP request router which can be used to dispatch requests to different handler functions.
func NewServices ¶
func NewServices(services ...interface{}) *Mux
func (*Mux) Handle ¶
func (m *Mux) Handle(method, pattern string, handler HandlerFunc)
Handle registers a new handler with method and path in the Mux. For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*Mux) HandleService ¶
func (*Mux) HandleServices ¶
func (m *Mux) HandleServices(ss ...interface{})
func (*Mux) SetBasicAuth ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a node on defined patterns that can be matched.
func (*Node) GetAllow ¶
GetAllow returns allow methods defined on the node
trie := New() trie.Define("/").Handle("GET", handler1) trie.Define("/").Handle("PUT", handler2) // trie.Match("/").Node.GetAllow() == "GET, PUT"
func (*Node) GetDescendants ¶
GetDescendants returns all descendants nodes.
func (*Node) GetHandler ¶
GetHandler ... GetHandler returns handler by method that defined on the node
trie := New() trie.Define("/api").Handle("GET", func handler1() {}) trie.Define("/api").Handle("PUT", func handler2() {}) trie.Match("/api").Node.GetHandler("GET").(func()) == handler1 trie.Match("/api").Node.GetHandler("PUT").(func()) == handler2
func (*Node) GetMethods ¶
GetMethods returns methods defined on the node
func (*Node) GetPattern ¶
GetPattern returns pattern defined on the node
type Options ¶
type Options struct { // Ignore case when matching URL path. IgnoreCase bool // If enabled, the trie will detect if the current path can't be matched but // a handler for the fixed path exists. // Matched.FPR will returns either a fixed redirect path or an empty string. // For example when "/api/foo" defined and matching "/api//foo", // The result Matched.FPR is "/api/foo". FixedPathRedirect bool // If enabled, the trie will detect if the current path can't be matched but // a handler for the path with (without) the trailing slash exists. // Matched.TSR will returns either a redirect path or an empty string. // For example if /foo/ is requested but a route only exists for /foo, the // client is redirected to /foo // For example when "/api/foo" defined and matching "/api/foo/", // The result Matched.TSR is "/api/foo". TrailingSlashRedirect bool }
Options is options for trie.