Documentation
¶
Index ¶
- Constants
- func HttpMethodCode(method string) int
- type AccessLogger
- type Captain
- type Context
- type Middleware
- type MiddlewareCallback
- type Router
- func (r *Router) Any(path string, h ...func(c *Captain))
- func (r *Router) Delete(path string, h ...func(c *Captain))
- func (r *Router) Excute(c *Context) bool
- func (r *Router) Get(path string, h ...func(c *Captain))
- func (r *Router) Options(path string, h ...func(c *Captain))
- func (r *Router) Post(path string, h ...func(c *Captain))
- func (r *Router) Put(path string, h ...func(c *Captain))
- type TestHelper
- type Zebra
- func (z *Zebra) Name() string
- func (z *Zebra) Run()
- func (z *Zebra) RunOnAddr(addr string)
- func (z *Zebra) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (z *Zebra) SetLogger(logger *log.Logger)
- func (z *Zebra) SetName(name string)
- func (z *Zebra) Use(m interface{})
- func (z *Zebra) UseFullFeatures()
Constants ¶
View Source
const ( MethodAny int = iota MethodGet MethodPost MethodPut MethodDelete MethodHead MethodOptions )
一组表示Http Method的常量。其中Any表示任意一种Http Method.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccessLogger ¶
type AccessLogger struct {
// contains filtered or unexported fields
}
服务访问日志
func (*AccessLogger) Callback ¶
func (logger *AccessLogger) Callback(cxt *Context)
func (*AccessLogger) EnableImmediate ¶
func (logger *AccessLogger) EnableImmediate()
开启即时模式:请求时输出日志而不是响应时输出
func (*AccessLogger) Excute ¶
func (logger *AccessLogger) Excute(cxt *Context) bool
TODO 不应该阻塞主程序,日志压入队列中异步执行
func (*AccessLogger) SetFormat ¶
func (logger *AccessLogger) SetFormat(format string)
设置日志格式,默认为 Combined 格式
func (*AccessLogger) SetLogger ¶
func (logger *AccessLogger) SetLogger(l *log.Logger)
使用给定的 Logger 记录服务访问日志
type Context ¶
type Context struct { Method int // Http Method Urlpath string // *http.Request 中的 URL Path Transfer map[string]interface{} // contains filtered or unexported fields }
Context 是 Middleware 的上下文对象
func (*Context) OriginalRequest ¶
获取原始的 *http.Request
func (*Context) OriginalResponseWriter ¶
func (c *Context) OriginalResponseWriter() http.ResponseWriter
获取原始的 http.ResponseWriter
func (*Context) ResponseWriter ¶
func (c *Context) ResponseWriter() http.ResponseWriter
type Middleware ¶
type Middleware interface { // Excute 用来执行当前 Middleware, // 返回 true 表示继续执行后续 Middleware, // 返回 false 阻止后续 Middleware 的执行。 Excute(*Context) bool }
zebra中的一切组件均为一个 Middleware.
func Mount ¶
func Mount(prefix string, m Middleware) Middleware
Mount 函数用于将一个 Middleware 挂载到一个路径前缀上。 该 Middleware 只会在指定 prefix 的URL子段下执行。
func ServeFavicon ¶
func ServeFavicon(path string) Middleware
func Wrap ¶
func Wrap(handler http.Handler) Middleware
type MiddlewareCallback ¶
type MiddlewareCallback interface { Middleware Callback(*Context) }
type TestHelper ¶
type TestHelper interface { AssertTrue(bool) AssertFalse(bool) AssertEqual(string, string) NewRequest(string, string) *http.Request }
func NewTestHelper ¶
func NewTestHelper(t *testing.T) TestHelper
type Zebra ¶
type Zebra struct {
// contains filtered or unexported fields
}
func NewWithServer ¶
func (*Zebra) UseFullFeatures ¶
func (z *Zebra) UseFullFeatures()
Click to show internal directories.
Click to hide internal directories.