core

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppInfo

type AppInfo interface {
	Logger() *zerolog.Logger
	Config() *Config
}

type Config

type Config struct {
	// 服务监听地址
	Host          string
	Debug         bool
	LoggerPath    string
	LoggerLevel   zerolog.Level
	Logger        *zerolog.Logger
	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()

func (*Config) IsValid

func (c *Config) IsValid() *Config

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 HandlerPool interface {
	SetNew(newFunc func() Handler)
	Acquire() Handler
	Release(h Handler)
}

type Meta

type Meta interface {
	// 生命周期 Init-> Flush/StreamWrite ->TryReset
	Init(w http.ResponseWriter, r *http.Request, params map[string]uint, app AppInfo)
	TryReset()
	Logger() *zerolog.Logger
	RemoteAddr() string
	RequestPath() string
	Query(string) string
	Params(string) string
	ParamsInt(string) int
	Method() rfc.Method
	SetStatus(status rfc.Status)
	Status() rfc.Status
	SetHeader(key, value string)
	AliveTime() time.Duration
	// 根据设计哲学,不提供cookie 相关处理函数
	// 必要附带信息请手动添加到header里,如各种权限token
	//SetCookie(key, value string)
	StreamRead(io.Writer)
	StreamWrite(io.Reader)
	Flush()
	Write([]byte)
	ResetBuf()
}

Meta 请求辅助处理单元

type MetaFunc

type MetaFunc func(m Meta)

元处理函数,非周期处理下对request 做处理

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)
	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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL