Documentation ¶
Index ¶
- Constants
- func RegisterOnGlobalStage(plugFunc ...HandlerFunc)
- func RegisterOnRequestStage(plugFunc ...HandlerFunc)
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortErr(err error)
- func (c *Context) Baggage(key string) string
- func (c *Context) Bind(r *http.Request, model interface{}, atom ...interface{}) error
- func (c *Context) BusiCode() int32
- func (c *Context) DefaultQuery(key, defaultValue string) string
- func (c *Context) Err() error
- func (c *Context) ForeachBaggage(handler func(key, val string) error) error
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetQuery(key string) (string, bool)
- func (c *Context) GetQueryArray(key string) ([]string, bool)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]interface{})
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) JSON(data interface{}, err error)
- func (c *Context) JSONAbort(data interface{}, err error)
- func (c *Context) JSONOrError(data interface{}, err error)
- func (c *Context) LoggingExtra(vals ...interface{})
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Next()
- func (c *Context) Query(key string) string
- func (c *Context) QueryArray(key string) []string
- func (c *Context) QueryInt(key string) int
- func (c *Context) QueryInt64(key string) int64
- func (c *Context) Raw(data interface{}, code int32)
- func (c *Context) Set(key string, value interface{})
- func (c *Context) SetBaggage(key, value string) context.Context
- func (c *Context) SetBusiCode(code int32)
- func (c *Context) TraceID() string
- type HandlerFunc
- type Option
- func Breaker(brk *breaker.Config) Option
- func CertFile(file string) Option
- func IdleTimeout(d time.Duration) Option
- func KeyFile(file string) Option
- func Limiter(lim *ratelimit.Config) Option
- func Logger(logger log.Kit) Option
- func Manager(re *registry.ServiceManager) Option
- func Name(serviceName string) Option
- func Port(port int) Option
- func ReadTimeout(d time.Duration) Option
- func RecoverPanic(rp bool) Option
- func Registry(r registry.Backend) Option
- func RequestBodyLogOff(b bool) Option
- func RespBodyLogMaxSize(size int) Option
- func Tags(tags map[string]string) Option
- func Tracer(tracer opentracing.Tracer) Option
- func WriteTimeout(d time.Duration) Option
- type Options
- type Param
- type Params
- type Responser
- type Router
- type RouterMgr
- func (mgr *RouterMgr) ANY(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) DELETE(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) GET(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) GETPOST(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) GROUP(relativePath string, handleFunc ...HandlerFunc) *RouterMgr
- func (mgr *RouterMgr) HEAD(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) OPTIONS(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) PATCH(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) POST(relativePath string, handlers ...HandlerFunc) Router
- func (mgr *RouterMgr) PUT(relativePath string, handlers ...HandlerFunc) Router
- type Server
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func RegisterOnGlobalStage ¶
func RegisterOnGlobalStage(plugFunc ...HandlerFunc)
plugins will be effect always
func RegisterOnRequestStage ¶
func RegisterOnRequestStage(plugFunc ...HandlerFunc)
plugins will be effect for a http request or a http route
Types ¶
type Context ¶
type Context struct { Request *http.Request Response Responser Params Params Path string // raw match path Peer string // 包含app_name的上游service_name Namespace string Ctx context.Context // for trace or others store Keys map[string]interface{} // contains filtered or unexported fields }
func (*Context) DefaultQuery ¶
func (*Context) ForeachBaggage ¶
遍历处理用户自定义的baggage信息
func (*Context) GetFloat64 ¶
func (*Context) GetStringMap ¶
func (*Context) GetStringMapString ¶
func (*Context) GetStringMapStringSlice ¶
func (*Context) GetStringSlice ¶
func (*Context) JSONOrError ¶
JSONOrError will handle error and write either JSON or error to response. good example: ```
resp, err := svc.MessageService() c.JSONOrError(resp, err)
``` bad example: ```
resp, err := svc.MessageService() c.JSON(resp, err)
```
func (*Context) LoggingExtra ¶
func (c *Context) LoggingExtra(vals ...interface{})
func (*Context) Query ¶
Query returns the keyed url query value if it exists, otherwise it returns an empty string `("")`. It is shortcut for `c.Request.URL.Query().Get(key)`
GET /path?id=1234&name=Manu&value= c.Query("id") == "1234" c.Query("name") == "Manu" c.Query("value") == "" c.Query("wtf") == ""
func (*Context) QueryArray ¶
func (*Context) QueryInt64 ¶
func (*Context) SetBaggage ¶
设置用户自定义信息到span baggage item中
func (*Context) SetBusiCode ¶
type HandlerFunc ¶
type HandlerFunc func(c *Context)
core plugin encapsulation
func PrintBodyLog ¶
func PrintBodyLog(printReq, printResp bool) HandlerFunc
func PrintRespBody
deprecated
func PrintRespBody(b bool) HandlerFunc
Deprecated: PrintRespBody func should not use anymore. Use PrintBodyLog func instead
type Option ¶
type Option func(*Options)
func IdleTimeout ¶
func Manager ¶
func Manager(re *registry.ServiceManager) Option
func ReadTimeout ¶
从连接被接受(accept)到request body完全被读取(如果你不读取body,那么时间截止到读完header为止) 包括了TCP消耗的时间,读header时间 对于 https请求,ReadTimeout 包括了TLS握手的时间
func RecoverPanic ¶
func WriteTimeout ¶
从request header的读取结束开始,到response write结束为止 (也就是 ServeHTTP 方法的声明周期)
type Router ¶
type Router interface { GROUP(string, ...HandlerFunc) *RouterMgr ANY(string, ...HandlerFunc) Router GET(string, ...HandlerFunc) Router POST(string, ...HandlerFunc) Router GETPOST(string, ...HandlerFunc) Router DELETE(string, ...HandlerFunc) Router PATCH(string, ...HandlerFunc) Router PUT(string, ...HandlerFunc) Router OPTIONS(string, ...HandlerFunc) Router HEAD(string, ...HandlerFunc) Router }
router
type RouterMgr ¶
type RouterMgr struct {
// contains filtered or unexported fields
}
func (*RouterMgr) ANY ¶
func (mgr *RouterMgr) ANY(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) DELETE ¶
func (mgr *RouterMgr) DELETE(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) GET ¶
func (mgr *RouterMgr) GET(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) GETPOST ¶
func (mgr *RouterMgr) GETPOST(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) GROUP ¶
func (mgr *RouterMgr) GROUP(relativePath string, handleFunc ...HandlerFunc) *RouterMgr
实现Router
func (*RouterMgr) HEAD ¶
func (mgr *RouterMgr) HEAD(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) OPTIONS ¶
func (mgr *RouterMgr) OPTIONS(relativePath string, handlers ...HandlerFunc) Router
func (*RouterMgr) PATCH ¶
func (mgr *RouterMgr) PATCH(relativePath string, handlers ...HandlerFunc) Router