Documentation
¶
Index ¶
- Constants
- type ErrorPages
- type FuncMap
- type Group
- func (g *Group) All(u string, h HandlerFunc)
- func (g *Group) Get(u string, h HandlerFunc)
- func (g *Group) NewHandler(method string, uri string, handler HandlerFunc)
- func (g *Group) Post(u string, h HandlerFunc)
- func (g *Group) Use(mw ...MiddlewareFunc)
- func (g *Group) UseGroup(uri string, group *Group)
- type HandlerFunc
- type HandlerPool
- type MiddlewareFunc
- type Pepper
- func (p *Pepper) All(u string, h HandlerFunc)
- func (p *Pepper) Get(u string, h HandlerFunc)
- func (p *Pepper) Listen(addr string) error
- func (p *Pepper) NewHandler(method string, uri string, handler HandlerFunc)
- func (p *Pepper) Post(u string, h HandlerFunc)
- func (p *Pepper) Static(uri string, dir string)
- func (p *Pepper) Use(mw ...MiddlewareFunc)
- func (p *Pepper) UseGroup(uri string, group *Group)
- type Request
- func (r *Request) GetCookie(key string) (cookie *http.Cookie, err error)
- func (r *Request) GetCookieValue(key string) string
- func (r *Request) GetForm() map[string][]string
- func (r *Request) GetFormStringValue(key string) string
- func (r *Request) GetFormValue(key string) ([]string, bool)
- func (r *Request) GetHeader(key string) string
- func (r *Request) GetJson(i interface{}) error
- func (r *Request) Query(key string) string
- func (r *Request) Scan(i interface{}) (err error)
- type Response
- func (r *Response) Json(v interface{}) (err error)
- func (r *Response) MustJson(code int, v interface{})
- func (r *Response) Redirect(url string)
- func (r *Response) RemoveCookie(name string)
- func (r *Response) SendErrorPage(code int) error
- func (r *Response) SetCookie(opt *http.Cookie)
- func (r *Response) SetHeader(key, value string)
- func (r *Response) SetStatusCode(code int)
- func (r *Response) Template(file string, tpl interface{}, fc FuncMap) error
- func (r *Response) Write(b []byte) (int, error)
- func (r *Response) WriteFile(file string, bufferSize int) (err error)
- func (r *Response) WriteReader(reader io.Reader, bufferSize int) error
- func (r *Response) WriteString(str string) (int, error)
- type TrieNode
- func (t *TrieNode) CallHandler(res Response, req *Request)
- func (t *TrieNode) GetHandlerFunc(method string, uri string) *HandlerFunc
- func (t *TrieNode) Insert(method string, uri string, handler *HandlerFunc)
- func (t *TrieNode) InsertByGroup(uri string, group *Group)
- func (t *TrieNode) Search(uri string) *HandlerPool
- func (t *TrieNode) SearchNode(uri string, callback func(*TrieNode)) *TrieNode
Constants ¶
View Source
const ( METHOD_ALL = "ALL" METHOD_GET = "GET" METHOD_POST = "POST" METHOD_HEAD = "HEAD" METHOD_PUT = "PUT" METHOD_DELETE = "DELETE" METHOD_CONNECT = "CONNECT" METHOD_OPTIONS = "OPTIONS" METHOD_TRACE = "TRACE" METHOD_PATCH = "PATCH" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorPages ¶
type ErrorPages struct {
Static struct {
NotFound string
Forbidden string
InternalServerError string
Other map[int]string
}
NotFound HandlerFunc
Forbidden HandlerFunc
InternalServerError HandlerFunc
Other map[int]HandlerFunc
}
func NewErrorPages ¶
func NewErrorPages() *ErrorPages
func (*ErrorPages) SendPage ¶
func (e *ErrorPages) SendPage(code int, res Response, req *Request) error
func (*ErrorPages) Set ¶
func (e *ErrorPages) Set(code int, file string)
func (*ErrorPages) SetHandler ¶
func (e *ErrorPages) SetHandler(code int, handler HandlerFunc)
type Group ¶
type Group struct {
Trie *TrieNode
}
func (*Group) Get ¶
func (g *Group) Get(u string, h HandlerFunc)
func (*Group) NewHandler ¶
func (g *Group) NewHandler(method string, uri string, handler HandlerFunc)
创建对应请求处理器
func (*Group) Post ¶
func (g *Group) Post(u string, h HandlerFunc)
func (*Group) Use ¶
func (g *Group) Use(mw ...MiddlewareFunc)
type HandlerPool ¶
type HandlerPool struct {
All *HandlerFunc
Get *HandlerFunc
Post *HandlerFunc
Head *HandlerFunc
Put *HandlerFunc
Delete *HandlerFunc
Connect *HandlerFunc
Options *HandlerFunc
Trace *HandlerFunc
Patch *HandlerFunc
}
处理程序池
func (*HandlerPool) GetHandlerFunc ¶
func (h *HandlerPool) GetHandlerFunc(method string) *HandlerFunc
获取对应处理函数
func (*HandlerPool) NewHandler ¶
func (h *HandlerPool) NewHandler(method string, handler HandlerFunc)
创建一种请求方式的处理器
type Pepper ¶
type Pepper struct {
// 调试模式
DebugMode bool
KeyFile string // 密钥文件路径 填写后会自动开启 HTTPS
CrtFile string // 证书文件路径 填写后会自动开启 HTTPS
// 错误页
ErrorPages *ErrorPages
// contains filtered or unexported fields
}
func (*Pepper) Get ¶
func (p *Pepper) Get(u string, h HandlerFunc)
func (*Pepper) NewHandler ¶
func (p *Pepper) NewHandler(method string, uri string, handler HandlerFunc)
创建对应请求处理器
func (*Pepper) Post ¶
func (p *Pepper) Post(u string, h HandlerFunc)
func (*Pepper) Use ¶
func (p *Pepper) Use(mw ...MiddlewareFunc)
type Request ¶
type Request struct {
Req *http.Request
Body io.ReadCloser
Method string
Path string
TrimPath string
Cookie string
Proto string
Host string
RemoteAddr string
ContentLength int64
// contains filtered or unexported fields
}
请求信息
func (*Request) GetCookieValue ¶
func (*Request) GetFormStringValue ¶
type Response ¶
type Response struct {
Resp http.ResponseWriter
ErrorPages *ErrorPages
Code int
// contains filtered or unexported fields
}
响应接口
func (*Response) RemoveCookie ¶
func (*Response) WriteReader ¶
通过 io.Reader 接口发送数据
type TrieNode ¶
type TrieNode struct {
Trusteeship bool
// 子节点
Next map[string]*TrieNode
// 此节点的上一个节点
Prev *TrieNode
Middleware []*MiddlewareFunc
// contains filtered or unexported fields
}
字典树
func (*TrieNode) CallHandler ¶
调用当前节点的对应处理的函数
func (*TrieNode) GetHandlerFunc ¶
func (t *TrieNode) GetHandlerFunc(method string, uri string) *HandlerFunc
获取对应处理函数
func (*TrieNode) Insert ¶
func (t *TrieNode) Insert(method string, uri string, handler *HandlerFunc)
添加处理函数到节点
func (*TrieNode) InsertByGroup ¶
func (*TrieNode) Search ¶
func (t *TrieNode) Search(uri string) *HandlerPool
通过URI查找树并返回 处理池 (*HandlePool)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.