Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// 服务监听地址
Host string
Debug bool
// log file path
LoggerPath string
LoggerLevel log.Level
Charset string `json:"charset,omitempty"`
TimeFormat string `json:"time_format,omitempty"`
PostMaxMemory int64
TlsCfg *tls.Config
// 最大连接数量 为非正数 则不限制
MaxConnections int
Router Router
}
func DefaultConfig ¶
func DefaultConfig() *Config
func (*Config) BuildLogger ¶
func (c *Config) BuildLogger()
type Handler ¶
type Handler interface {
// 请求生命周期 init -> get/post/etc -> finished -> onResponse(返回处理) -> tryReset
// 一旦某一周期返回会触发OnError 接口 并结束
// init 方法最好调用TryRest 确保重置过
Init(m Meta) error
Get() (interface{}, error)
Post() (interface{}, error)
Put() (interface{}, error)
Patch() (interface{}, error)
Head() (interface{}, error)
Options() (interface{}, error)
Delete() (interface{}, error)
Trace() (interface{}, error)
Finished() error
OnResponse(data interface{})
OnError(err error)
// TryReset 方法最好把继承的所有handler 的TryReset调用一遍
TryReset() // 尝试reset 历史信息 若没有重置,则直接重置, 若有则不做任何事情
Meta() Meta
}
type HandlerPool ¶
type Meta ¶
type Meta interface {
http.ResponseWriter
// 生命周期 Init-> Write/Flush/StreamWrite ->TryReset
Init(w http.ResponseWriter, r *http.Request, params map[string]uint)
TryReset()
RemoteAddr() string
RequestPath() string
Method() rfc.Method
ReadJson(ptr interface{}) error
UnmarshalBody(ptr interface{}, fc func([]byte, interface{}) error) error
Query(string) string
GetHeader(string) string
Params(string) string
ParamsInt(string) int
Status() rfc.Status
SetHeader(key, value string)
AliveTime() time.Duration
// 根据设计哲学,不提供cookie 相关处理函数
// 必要附带信息请手动添加到header里,如各种权限token
//SetCookie(key, value string)
StreamRead(io.Writer) (int64, error)
StreamWrite(io.Reader) (int64, error)
Request() *http.Request
}
Meta 请求辅助处理单元
type RequestLifeCycle ¶ added in v0.3.2
type RequestLifeCycle = func(interface{}, Meta)
type Router ¶
type Router interface {
SetRequestLifeCycle(cycle RequestLifeCycle)
Set(prefix string, fc interface{}, allowedMethods ...rfc.Method) Router
Static(prefix string, directory string)
SubRouter(name string) Router
ServeHTTP(http.ResponseWriter, *http.Request)
SetStatusFunc(status rfc.Status, rf MetaFunc)
SetNotFoundFunc(fc MetaFunc)
// 对于内部panic错误, 返回500 错误 并执行相应回调
SetInternalErrorFunc(fc MetaFunc)
String() string
AbsPath() string
}
Click to show internal directories.
Click to hide internal directories.