Documentation ¶
Index ¶
- Variables
- func CheckNoLogParams(origin string) bool
- func LogParams(ctx *WebContext)
- func SetTrace(ctx *WebContext)
- type App
- func (app *App) PbRPCServer() *PbRPCServer
- func (app *App) RunPbRPCServer()
- func (app *App) RunWebServer()
- func (app *App) SetNoLogParams(path ...string)
- func (app *App) SetNoLogParamsPrefix(path ...string)
- func (app *App) SetNoLogParamsSuffix(path ...string)
- func (app *App) Use(fc ...func())
- func (app *App) WebServer() *WebServer
- type AppConfig
- type AppOption
- type Context
- type DataContext
- type HandlerFunc
- type LogContext
- func (ctx *LogContext) Alarm(msg interface{})
- func (ctx *LogContext) ErrorF(template string, args ...interface{})
- func (ctx *LogContext) Field(key string, value interface{}) glogs.Field
- func (ctx *LogContext) GetClientIP() string
- func (ctx *LogContext) GetTraceId() string
- func (ctx *LogContext) InfoF(template string, args ...interface{})
- func (ctx *LogContext) StartSpan() glogs.Span
- func (ctx *LogContext) StartSpanP(span glogs.Span, name string) glogs.Span
- func (ctx *LogContext) StartSpanR(name string) glogs.Span
- func (ctx *LogContext) StopSpan(span glogs.Span)
- func (ctx *LogContext) WarnF(template string, args ...interface{})
- type LoggerContext
- type MemoryContext
- func (c *MemoryContext) Get(key string) (value interface{}, exists bool)
- func (c *MemoryContext) GetBool(key string) (b bool)
- func (c *MemoryContext) GetDuration(key string) (d time.Duration)
- func (c *MemoryContext) GetFloat64(key string) (f64 float64)
- func (c *MemoryContext) GetInt(key string) (i int)
- func (c *MemoryContext) GetInt64(key string) (i64 int64)
- func (c *MemoryContext) GetString(key string) (s string)
- func (c *MemoryContext) GetStringMap(key string) (sm map[string]interface{})
- func (c *MemoryContext) GetStringMapString(key string) (sms map[string]string)
- func (c *MemoryContext) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *MemoryContext) GetStringSlice(key string) (ss []string)
- func (c *MemoryContext) GetTime(key string) (t time.Time)
- func (c *MemoryContext) MustGet(key string) interface{}
- func (c *MemoryContext) Set(key string, value interface{})
- type PbRPCContext
- func (c *PbRPCContext) Deadline() (deadline time.Time, ok bool)
- func (c *PbRPCContext) Done() <-chan struct{}
- func (c *PbRPCContext) Err() error
- func (c *PbRPCContext) Next()
- func (c *PbRPCContext) ReadPackage() (*grpcx.Package, error)
- func (c *PbRPCContext) Value(key interface{}) interface{}
- func (c *PbRPCContext) WritePackage(pkg *grpcx.Package) (int, error)
- type PbRPCHandlerFunc
- type PbRPCServer
- type RouterRegister
- type Server
- func (gs *Server) CountAvailableWorkers() uint32
- func (gs *Server) CountBusyWorkers() uint32
- func (gs *Server) Run(listen ...string) (err error)
- func (gs *Server) RunGrace(addr string, timeouts ...time.Duration) error
- func (gs *Server) RunUnix(path ...string) (err error)
- func (gs *Server) SetAcceptErrorHandler(h func(error))
- func (gs *Server) SetLogger(logger *zap.Logger)
- func (gs *Server) SetReadTimeout(ms int64)
- func (gs *Server) SetRejectHandler(h func(net.Conn, error))
- func (gs *Server) SetWriteTimeout(ms int64)
- type WebContext
- type WebHandlerFunc
- type WebRoute
- func (wrc *WebRoute) Any(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) GET(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) Group(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) POST(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) PUT(pattern string, handlers ...WebHandlerFunc) WebRouter
- func (wrc *WebRoute) Static(relativePath, root string) WebRouter
- func (wrc *WebRoute) StaticFS(relativePath string, fs http.FileSystem) WebRouter
- func (wrc *WebRoute) StaticFile(relativePath, filepath string) WebRouter
- func (wrc *WebRoute) Use(middleware ...WebHandlerFunc) WebRouter
- type WebRouter
- type WebServer
- func (webServer *WebServer) Delims(left, right string) *WebServer
- func (webServer *WebServer) HandleContext(wc *WebContext)
- func (webServer *WebServer) NoMethod(handlers ...WebHandlerFunc)
- func (webServer *WebServer) NoRoute(handlers ...WebHandlerFunc)
- func (webServer *WebServer) RegisterRouter(rr RouterRegister)
- func (webServer *WebServer) RunGrace(addr string, timeouts ...time.Duration) error
- func (webServer *WebServer) SecureJsonPrefix(prefix string) *WebServer
- func (webServer *WebServer) Use(middleware ...WebHandlerFunc) WebRouter
Constants ¶
This section is empty.
Variables ¶
var DefaultWebServerMiddlewares = []WebHandlerFunc{ LogParams, SetTrace, ginHandler2WebHandler(gin.Recovery()), recovery, }
DefaultWebServerMiddlewares 默认的Http Server中间件 其实应该保证TowerLogware 不panic,但是无法保证,多一个recovery来保证业务日志崩溃后依旧有访问日志
Functions ¶
func CheckNoLogParams ¶
CheckNoLogParams 判断是否需要打印入参出参日志, 不需要打印返回true
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) SetNoLogParams ¶
SetNoLogParams 设置不需要打印的路由
func (*App) SetNoLogParamsPrefix ¶
SetNoLogParamsPrefix 设置不需要打印入参和出参的路由前缀
func (*App) SetNoLogParamsSuffix ¶
SetNoLogParamsSuffix 设置不需要打印的入参和出参的路由后缀
type Context ¶
type Context interface { context.Context DataContext LoggerContext }
Context is the carrier of request and response
type DataContext ¶
type DataContext interface { Set(key string, value interface{}) Get(key string) (value interface{}, exists bool) MustGet(key string) interface{} GetString(key string) string GetBool(key string) bool GetInt(key string) int GetInt64(key string) int64 GetFloat64(key string) float64 GetTime(key string) time.Time GetDuration(key string) time.Duration GetStringSlice(key string) []string GetStringMap(key string) map[string]interface{} GetStringMapString(key string) map[string]string GetStringMapStringSlice(key string) map[string][]string }
DataContext interface the extend of context.Context.Value(key string) (value interface{})
type LogContext ¶
type LogContext struct { RspHTTPStatusCode int ErrMsg string // contains filtered or unexported fields }
LogContext logger
func NewLogContext ¶
func NewLogContext(req *http.Request, traceId string) *LogContext
NewLogContext new obj
func (*LogContext) ErrorF ¶
func (ctx *LogContext) ErrorF(template string, args ...interface{})
func (*LogContext) InfoF ¶
func (ctx *LogContext) InfoF(template string, args ...interface{})
func (*LogContext) StartSpan ¶
func (ctx *LogContext) StartSpan() glogs.Span
StartSpan StopSpan StartSpanP StartSpanR 开启,关闭,通过上级span开启span, 通过request开启span
func (*LogContext) StartSpanP ¶
func (*LogContext) StartSpanR ¶
func (ctx *LogContext) StartSpanR(name string) glogs.Span
func (*LogContext) StopSpan ¶
func (ctx *LogContext) StopSpan(span glogs.Span)
func (*LogContext) WarnF ¶
func (ctx *LogContext) WarnF(template string, args ...interface{})
type LoggerContext ¶
type LoggerContext interface { InfoF(template string, args ...interface{}) WarnF(template string, args ...interface{}) ErrorF(template string, args ...interface{}) Field(key string, value interface{}) glogs.Field // Alarm 告警 Alarm(msg interface{}) // StartSpan StopSpan StartSpanP StartSpanR 开启,关闭,通过上级span开启span, 通过request开启span StartSpan() glogs.Span StopSpan(span glogs.Span) StartSpanP(span glogs.Span, name string) glogs.Span StartSpanR(name string) glogs.Span }
LoggerContext 包含链路, 日志, 告警
type MemoryContext ¶
type MemoryContext struct {
// contains filtered or unexported fields
}
MemoryContext store data tor memory
func (*MemoryContext) Get ¶
func (c *MemoryContext) Get(key string) (value interface{}, exists bool)
Get returns the value for the given key, ie: (value, true). If the value does not exists it returns (nil, false)
func (*MemoryContext) GetBool ¶
func (c *MemoryContext) GetBool(key string) (b bool)
GetBool returns the value associated with the key as a boolean.
func (*MemoryContext) GetDuration ¶
func (c *MemoryContext) GetDuration(key string) (d time.Duration)
GetDuration returns the value associated with the key as a duration.
func (*MemoryContext) GetFloat64 ¶
func (c *MemoryContext) GetFloat64(key string) (f64 float64)
GetFloat64 returns the value associated with the key as a float64.
func (*MemoryContext) GetInt ¶
func (c *MemoryContext) GetInt(key string) (i int)
GetInt returns the value associated with the key as an integer.
func (*MemoryContext) GetInt64 ¶
func (c *MemoryContext) GetInt64(key string) (i64 int64)
GetInt64 returns the value associated with the key as an integer.
func (*MemoryContext) GetString ¶
func (c *MemoryContext) GetString(key string) (s string)
GetString returns the value associated with the key as a string.
func (*MemoryContext) GetStringMap ¶
func (c *MemoryContext) GetStringMap(key string) (sm map[string]interface{})
GetStringMap returns the value associated with the key as a map of interfaces.
func (*MemoryContext) GetStringMapString ¶
func (c *MemoryContext) GetStringMapString(key string) (sms map[string]string)
GetStringMapString returns the value associated with the key as a map of strings.
func (*MemoryContext) GetStringMapStringSlice ¶
func (c *MemoryContext) GetStringMapStringSlice(key string) (smss map[string][]string)
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func (*MemoryContext) GetStringSlice ¶
func (c *MemoryContext) GetStringSlice(key string) (ss []string)
GetStringSlice returns the value associated with the key as a slice of strings.
func (*MemoryContext) GetTime ¶
func (c *MemoryContext) GetTime(key string) (t time.Time)
GetTime returns the value associated with the key as time.
func (*MemoryContext) MustGet ¶
func (c *MemoryContext) MustGet(key string) interface{}
MustGet returns the value for the given key if it exists, otherwise it panics.
func (*MemoryContext) Set ¶
func (c *MemoryContext) Set(key string, value interface{})
Set is used to store a new key/value pair exclusively for this context. It also lazy initializes c.data if it was not used previously.
type PbRPCContext ¶
type PbRPCContext struct { *LogContext *MemoryContext // contains filtered or unexported fields }
PbRPCContext pbrpc context
func (*PbRPCContext) Deadline ¶
func (c *PbRPCContext) Deadline() (deadline time.Time, ok bool)
Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.
func (*PbRPCContext) Done ¶
func (c *PbRPCContext) Done() <-chan struct{}
Done returns a channel that's closed when work done on behalf of this context should be canceled. Done may return nil if this context can never be canceled. Successive calls to Done return the same value.
func (*PbRPCContext) Err ¶
func (c *PbRPCContext) Err() error
Err returns a non-nil error value after Done is closed, successive calls to Err return the same error. If Done is not yet closed, Err returns nil. If Done is closed, Err returns a non-nil error explaining why: Canceled if the context was canceled or DeadlineExceeded if the context's deadline passed.
func (*PbRPCContext) ReadPackage ¶
func (c *PbRPCContext) ReadPackage() (*grpcx.Package, error)
ReadPackage return a package
func (*PbRPCContext) Value ¶
func (c *PbRPCContext) Value(key interface{}) interface{}
Value returns the value associated with this context for key, or nil if no value is associated with key. Successive calls to Value with the same key returns the same result.
func (*PbRPCContext) WritePackage ¶
func (c *PbRPCContext) WritePackage(pkg *grpcx.Package) (int, error)
WritePackage write a package
type PbRPCHandlerFunc ¶
type PbRPCHandlerFunc func(*PbRPCContext)
PbRPCHandlerFunc handler for PbRPC
type PbRPCServer ¶
type PbRPCServer struct { Server // contains filtered or unexported fields }
PbRPCServer struct
func NewPbRPCServer ¶
func NewPbRPCServer() *PbRPCServer
NewPbRPCServer create new PbRPCServer with default configuration
func (*PbRPCServer) AddHandler ¶
func (pbs *PbRPCServer) AddHandler(handlers ...PbRPCHandlerFunc)
AddHandler 添加处理函数
type Server ¶
type Server struct { // Exported fields Logger *zap.Logger Mode string MaxWorker uint32 PrepareWorker uint32 ReadTimeout time.Duration WriteTimeout time.Duration // Exported Method needs to apply RequestHandler func(con net.Conn) // contains filtered or unexported fields }
Server 提供较为通用的服务器程序
func (*Server) CountAvailableWorkers ¶
func (*Server) CountBusyWorkers ¶
func (*Server) SetAcceptErrorHandler ¶
func (*Server) SetReadTimeout ¶
func (*Server) SetWriteTimeout ¶
type WebContext ¶
type WebContext struct { *gin.Context *LogContext }
WebContext http 的context WebContext 继承了 gin.Context, 并且扩展了日志功能
func NewWebContext ¶
func NewWebContext(ginContext *gin.Context) *WebContext
NewWebContext 创建 http context
type WebRoute ¶
type WebRoute struct { RouterGroup *gin.RouterGroup // contains filtered or unexported fields }
WebRoute struct 它实现了gin.IRoutes, gin.IRoute
func (*WebRoute) Any ¶
func (wrc *WebRoute) Any(pattern string, handlers ...WebHandlerFunc) WebRouter
Any 注册所有的方法
func (*WebRoute) DELETE ¶
func (wrc *WebRoute) DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter
DELETE 注册DELETE方法
func (*WebRoute) GET ¶
func (wrc *WebRoute) GET(pattern string, handlers ...WebHandlerFunc) WebRouter
GET 注册GET方法
func (*WebRoute) Group ¶
func (wrc *WebRoute) Group(pattern string, handlers ...WebHandlerFunc) WebRouter
Group creates a new web router group
func (*WebRoute) HEAD ¶
func (wrc *WebRoute) HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter
HEAD 注册HEAD方法
func (*WebRoute) OPTIONS ¶
func (wrc *WebRoute) OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter
OPTIONS 注册OPTIONS方法
func (*WebRoute) PATCH ¶
func (wrc *WebRoute) PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter
PATCH 注册PATCH方法
func (*WebRoute) POST ¶
func (wrc *WebRoute) POST(pattern string, handlers ...WebHandlerFunc) WebRouter
POST 注册POST方法
func (*WebRoute) PUT ¶
func (wrc *WebRoute) PUT(pattern string, handlers ...WebHandlerFunc) WebRouter
PUT 注册PUT方法
func (*WebRoute) StaticFS ¶
func (wrc *WebRoute) StaticFS(relativePath string, fs http.FileSystem) WebRouter
StaticFS 静态文件
func (*WebRoute) StaticFile ¶
StaticFile 静态文件
func (*WebRoute) Use ¶
func (wrc *WebRoute) Use(middleware ...WebHandlerFunc) WebRouter
Use attachs a global middleware to the router. ie. the middleware attached though Use() will be included in the handlers chain for every single request. Even 404, 405, static files... For example, this is the right place for a logger or error management middleware.
type WebRouter ¶
type WebRouter interface { // Group gin.IRoute.Group Group(string, ...WebHandlerFunc) WebRouter // Use gin.IRoutes.Use Use(...WebHandlerFunc) WebRouter Any(pattern string, handlers ...WebHandlerFunc) WebRouter GET(pattern string, handlers ...WebHandlerFunc) WebRouter POST(pattern string, handlers ...WebHandlerFunc) WebRouter DELETE(pattern string, handlers ...WebHandlerFunc) WebRouter PATCH(pattern string, handlers ...WebHandlerFunc) WebRouter PUT(pattern string, handlers ...WebHandlerFunc) WebRouter OPTIONS(pattern string, handlers ...WebHandlerFunc) WebRouter HEAD(pattern string, handlers ...WebHandlerFunc) WebRouter StaticFile(relativePath, filepath string) WebRouter Static(relativePath, root string) WebRouter StaticFS(relativePath string, fs http.FileSystem) WebRouter }
WebRouter interface WebRequest Router 它合并了 gin.IRoute 和 gin.IRoutes
type WebServer ¶
WebServer 基于http协议的服务 这里的实现是基于gin框架, 封装了gin的所有的方法 gin 的核心是高效路由, 但是gin.Engine和gin.IRouter(s)的高耦合让我们无法复用, gin的作者认为它的路由就是引擎吧
func (*WebServer) HandleContext ¶
func (webServer *WebServer) HandleContext(wc *WebContext)
HandleContext re-enter a context that has been rewritten. This can be done by setting c.Request.URL.Path to your new target. Disclaimer: You can loop yourself to death with this, use wisely.
func (*WebServer) NoMethod ¶
func (webServer *WebServer) NoMethod(handlers ...WebHandlerFunc)
NoMethod sets the handlers called when... TODO. 重写gin方法
func (*WebServer) NoRoute ¶
func (webServer *WebServer) NoRoute(handlers ...WebHandlerFunc)
NoRoute adds handlers for NoRoute. It return a 404 code by default. 重写gin方法
func (*WebServer) RegisterRouter ¶
func (webServer *WebServer) RegisterRouter(rr RouterRegister)
RegisterRouter 注册路由
func (*WebServer) SecureJsonPrefix ¶
SecureJsonPrefix sets the secureJsonPrefix used in Context.SecureJSON. 重写gin方法
func (*WebServer) Use ¶
func (webServer *WebServer) Use(middleware ...WebHandlerFunc) WebRouter
Use adds middleware to the group, see example code in github.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmdx
module
|
|
Package gcal 提供了一个支持多种交互协议和打包格式的扩展包。
|
Package gcal 提供了一个支持多种交互协议和打包格式的扩展包。 |
context
Package context 提供每次 RAL 请求的上下文对象,主要用来输出日志。
|
Package context 提供每次 RAL 请求的上下文对象,主要用来输出日志。 |
converter
Package converter 提供了一系列对请求的数据序列化和响应的数据格式化方法
|
Package converter 提供了一系列对请求的数据序列化和响应的数据格式化方法 |
protocol
Package protocol 提供了 HTTP、HTTPS、NSHead、ProtoBuffer 协议支持
|
Package protocol 提供了 HTTP、HTTPS、NSHead、ProtoBuffer 协议支持 |
service
Package service 提供了一些列资源管理的方法
|
Package service 提供了一些列资源管理的方法 |
Package glogs is a global internal glogs glogs: this is extend package, use https://github.com/uber-go/zap
|
Package glogs is a global internal glogs glogs: this is extend package, use https://github.com/uber-go/zap |
logger
Package logger is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
|
Package logger is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify. |
Package gversion storage versions info for laya
|
Package gversion storage versions info for laya |
laya
module
|