Documentation ¶
Index ¶
- Constants
- Variables
- func Combined(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
- func GetClientIP(ctx *fasthttp.RequestCtx) string
- func GetDailyLogWriter(filename string) (*rotatelogs.RotateLogs, error)
- func IsEnvOff(name string) bool
- func RegisterErrorProcessors(processors ...ErrorProcessor)
- func RegisterPostProcessor(processors ...PostProcessor)
- func RegisterPreProcessor(processors ...PreProcessor)
- func Short(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
- func Tiny(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
- type Arg
- type Context
- type DummyService
- type Echo
- type Encrypt
- type EncryptReq
- type EncryptRsp
- type ErrorProcessor
- type ErrorProcessorFn
- type Jpg
- type LogPrint
- type LogType
- type P1Sign
- type P1SignReq
- type P1SignRsp
- type PanicProcessor
- type PanicProcessorFn
- type PanicService
- type PostProcessor
- type PostProcessorFn
- type PreProcessor
- type PreProcessorFn
- type Router
- type RouterConfig
- type RouterConfigFn
- func WithAccessLogDir(v string) RouterConfigFn
- func WithErrorProcessor(v ErrorProcessor) RouterConfigFn
- func WithFastHTTPServer(server *fasthttp.Server) RouterConfigFn
- func WithMaxRequestBodySize(maxRequestBodySize int) RouterConfigFn
- func WithNotFoundHandler(v func(ctx *Context)) RouterConfigFn
- func WithPanicProcessor(v PanicProcessor) RouterConfigFn
- func WithPostProcessor(v PostProcessor) RouterConfigFn
- func WithPreProcessor(v PreProcessor) RouterConfigFn
- type Rsp
- type Service
- type Status
- type Version
Constants ¶
const (
ResultSendFile = "__ResultSendFile"
)
Variables ¶
var ( DefaultPreProcessors []PreProcessor DefaultPostProcessors []PostProcessor DefaultErrorProcessors []ErrorProcessor )
var LogTypeEnv = func() LogType { switch v := os.Getenv("LOG_TYPE"); strings.ToLower(v) { case "0", "off", "no": return LogOff case "async": return LogAsync default: return LogOn } }()
var Pool = &bytebufferpool.Pool{}
Functions ¶
func Combined ¶
func Combined(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
Combined format: [<time>] <remote-addr> | <HTTP/http-version> | <method> <url> <request body size> - <status> <response body size> <response-time us> | <user-agent> [2017-05-31 13:27:28] 127.0.0.1:54082 | HTTP/1.1 | GET /hello 12345 - 200 12345 48.279µs | Paw/3.1.1 (Macintosh; OS X/10.12.5) GCDHTTPRequest
func GetClientIP ¶
func GetClientIP(ctx *fasthttp.RequestCtx) string
GetClientIP returns the originating IP for a request.
func GetDailyLogWriter ¶
func GetDailyLogWriter(filename string) (*rotatelogs.RotateLogs, error)
GetDailyLogWriter 日志文件切割,按天
func RegisterErrorProcessors ¶
func RegisterErrorProcessors(processors ...ErrorProcessor)
func RegisterPostProcessor ¶
func RegisterPostProcessor(processors ...PostProcessor)
func RegisterPreProcessor ¶
func RegisterPreProcessor(processors ...PreProcessor)
func Short ¶
func Short(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
Short format: <remote-addr> | <HTTP/:http-version> | <method> <url> - <status> - <response-time us> 127.0.0.1:53324 | HTTP/1.1 | GET /hello - 200 - 44.8µs
func Tiny ¶
func Tiny(req fasthttp.RequestHandler, logFunc LogPrint) fasthttp.RequestHandler
Tiny format: <method> <url> - <status> - <response-time us> GET / - 200 - 11.925 us
Types ¶
type Arg ¶
type Arg struct { Config string `flag:"c" usage:"yaml Config filepath"` Addr string `val:":14142"` Init bool `usage:"init example conf.yml/ctl and then exit"` Version bool `usage:"print version then exit"` ReusePort bool `usage:"Reuse port"` MaxProcs int `usage:"GOMAXPROCS"` }
func (*Arg) VersionInfo ¶
type Context ¶
type Context struct { Req interface{} Rsp interface{} Ctx *fasthttp.RequestCtx ServiceName string Returners []bytebufferpool.PoolReturner }
func (*Context) AppendPoolReturner ¶
func (c *Context) AppendPoolReturner(r bytebufferpool.PoolReturner)
func (*Context) ApplyPoolBuf ¶
type DummyService ¶
type DummyService struct{}
func (*DummyService) CreateReq ¶
func (d *DummyService) CreateReq() (interface{}, error)
func (*DummyService) Process ¶
func (d *DummyService) Process(*Context) (interface{}, error)
type Echo ¶
type Echo struct{ DummyService }
type Encrypt ¶
type Encrypt struct{ DummyService }
type EncryptReq ¶
type EncryptReq struct { TransId string `json:"transId"` AppId string `json:"appId"` KeyId string `json:"keyId"` Mode string `json:"mode"` Padding string `json:"padding"` PlainText string `json:"plainText"` }
func (EncryptReq) MarshalEasyJSON ¶
func (v EncryptReq) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*EncryptReq) UnmarshalEasyJSON ¶
func (v *EncryptReq) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type EncryptRsp ¶
type EncryptRsp struct {
Data string `json:"data"`
}
func (EncryptRsp) MarshalEasyJSON ¶
func (v EncryptRsp) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*EncryptRsp) UnmarshalEasyJSON ¶
func (v *EncryptRsp) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type ErrorProcessor ¶
type ErrorProcessorFn ¶
func (ErrorProcessorFn) ProcessError ¶
func (f ErrorProcessorFn) ProcessError(dtx *Context, err error) error
type Jpg ¶
type Jpg struct{ DummyService }
type LogPrint ¶
type LogPrint func(format string, a ...interface{})
LogPrint logs a message using the given format and optional arguments. The usage of format and arguments is similar to that for fmt.Printf(). LogPrint should be thread safe.
type P1Sign ¶
type P1Sign struct{ DummyService }
type P1SignReq ¶
func (P1SignReq) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*P1SignReq) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type P1SignRsp ¶
type P1SignRsp struct {
Source string `json:"source"`
}
func (P1SignRsp) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*P1SignRsp) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type PanicProcessor ¶
type PanicProcessor interface {
PanicProcess(dtx *Context, recovered interface{})
}
type PanicProcessorFn ¶
type PanicProcessorFn func(dtx *Context, recovered interface{})
func (PanicProcessorFn) PanicProcess ¶
func (f PanicProcessorFn) PanicProcess(dtx *Context, recovered interface{})
type PanicService ¶
type PanicService struct{ DummyService }
func (*PanicService) Process ¶
func (p *PanicService) Process(dtx *Context) (interface{}, error)
type PostProcessor ¶
type PostProcessorFn ¶
func (PostProcessorFn) PostProcess ¶
func (f PostProcessorFn) PostProcess(dtx *Context) error
type PreProcessor ¶
type PreProcessorFn ¶
func (PreProcessorFn) PreProcess ¶
func (f PreProcessorFn) PreProcess(dtx *Context) error
type Router ¶
type Router struct { Config *RouterConfig // contains filtered or unexported fields }
type RouterConfig ¶
type RouterConfig struct { PanicProcessor PanicProcessor AccessLogDir string PreProcessors []PreProcessor PostProcessors []PostProcessor ErrorProcessors []ErrorProcessor NotFoundHandler func(dtx *Context) MaxRequestBodySize int *fasthttp.Server }
type RouterConfigFn ¶
type RouterConfigFn func(*RouterConfig)
func WithAccessLogDir ¶
func WithAccessLogDir(v string) RouterConfigFn
func WithErrorProcessor ¶
func WithErrorProcessor(v ErrorProcessor) RouterConfigFn
func WithFastHTTPServer ¶
func WithFastHTTPServer(server *fasthttp.Server) RouterConfigFn
WithFastHTTPServer set customized fasthttp.Server, warn: Handler will be ignored
func WithMaxRequestBodySize ¶
func WithMaxRequestBodySize(maxRequestBodySize int) RouterConfigFn
WithMaxRequestBodySize set Maximum request body size.
func WithNotFoundHandler ¶
func WithNotFoundHandler(v func(ctx *Context)) RouterConfigFn
func WithPanicProcessor ¶
func WithPanicProcessor(v PanicProcessor) RouterConfigFn
func WithPostProcessor ¶
func WithPostProcessor(v PostProcessor) RouterConfigFn
func WithPreProcessor ¶
func WithPreProcessor(v PreProcessor) RouterConfigFn
type Rsp ¶
type Rsp struct { Data interface{} `json:"data,omitempty"` Message string `json:"message,omitempty"` Status int `json:"status,omitempty"` }
func (Rsp) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Rsp) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
type Status ¶
type Status struct{ DummyService }