Documentation
¶
Overview ¶
Package engine
Engine for HTTP/Plnack When using engine type=plnack, Plnack data will return
innerEngine which is for service connect by tcp using RPC by plnack-proto MiddleWare中间件 支持从配置文件加载,支持通过so的plugins机制加载 MiddleWare的so库需要符合统一的入口函数,并且放置于指定的目录下lib
Package engine ¶
Package engine
Index ¶
- Constants
- Variables
- func AddModule(m Module)
- func Hooks(s *Engine)
- func LoadModules() []string
- func MiddleCache(handle gin.HandlerFunc) gin.HandlerFunc
- func MiddleWareAuth() gin.HandlerFunc
- func MiddleWareCors() gin.HandlerFunc
- func MiddlewareNoMethod() gin.HandlerFunc
- func MiddlewareNoRoute() gin.HandlerFunc
- func MiddlewarePlnack() gin.HandlerFunc
- func RegisterSignals(s *http.Server, sigChan chan os.Signal)
- func SaveMiddleWareConfig() error
- type Engine
- func (e *Engine) DELETE(r string, handler ...gin.HandlerFunc)
- func (e *Engine) GET(r string, handler ...gin.HandlerFunc)
- func (e *Engine) GetEngine() *gin.Engine
- func (e *Engine) Group(r string, ware ...gin.HandlerFunc) *gin.RouterGroup
- func (e *Engine) Handle(method, r string, handler ...gin.HandlerFunc)
- func (e *Engine) Init()
- func (e *Engine) LoadMiddleWare(m []gin.HandlerFunc)
- func (e *Engine) POST(r string, handler ...gin.HandlerFunc)
- func (e *Engine) PUT(r string, handler ...gin.HandlerFunc)
- func (e *Engine) Run() error
- func (e *Engine) RunServer() error
- func (e *Engine) RunServerTLS(cert, key string) error
- func (e *Engine) SetHeadersMap(m map[string]string)
- type EngineConfig
- type MiddleWareConfig
- type Module
- type RouterGroup
Constants ¶
View Source
const ( PLNACK_PROTO = "+plnack" HtmlTmpl = "web/tmpl/**/*" StaticPath = "web/static" TmplPath = "web/tmpl" )
View Source
const ( ModulePath = "modules" ModuleLookup = "Module" So = ".so" )
View Source
const ( MiddleWare = "[MiddleWare]" PluginsPath = "lib" )
View Source
const ( DefaultExpire = time.Hour * 24 * 7 PageExpire = time.Hour * 24 )
View Source
const ( GlobalMode = "global" RouteMode = "route" MiddleConfigRoot = "conf" MiddleConfigFile = "middleware.pig" )
View Source
const ( Stop = syscall.SIGUSR2 ForceStop = syscall.SIGINT Reload = syscall.SIGUSR1 APPName = "[Apollo]" )
View Source
const (
ApolloAuthCode = "ApolloAuthCode"
)
View Source
const (
KeyPlnack = "plnack"
)
Variables ¶
View Source
var ApolloModules []Module
ApolloModules 全局记录的动态路由模块信息
View Source
var DefaultMiddleWare = []MiddleWareConfig{ { Name: "log", Mode: GlobalMode, Active: true, }, { Name: "recovery", Mode: GlobalMode, Active: true, }, { Name: "plnack", Mode: GlobalMode, Active: false, }, { Name: "cors", Mode: GlobalMode, Active: true, }, }
View Source
var MiddleWareMap = map[string]gin.HandlerFunc{ "log": gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string { var statusColor, methodColor, resetColor string if param.IsOutputColor() { statusColor = param.StatusCodeColor() methodColor = param.MethodColor() resetColor = param.ResetColor() } if param.Latency > time.Minute { param.Latency = param.Latency.Truncate(time.Second) } return fmt.Sprintf("[Apollo] %v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s", param.TimeStamp.Format("2006/01/02 - 15:04:05"), statusColor, param.StatusCode, resetColor, param.Latency, param.ClientIP, methodColor, param.Method, resetColor, param.Path, param.ErrorMessage, ) }), "recovery": gin.Recovery(), "cors": MiddleWareCors(), "plnack": MiddlewarePlnack(), "gzip": gzip.Gzip(gzip.BestCompression, gzip.WithExcludedPaths([]string{"/api/"})), }
View Source
var PreInjectMiddle []MiddleWareConfig
Functions ¶
func LoadModules ¶ added in v1.1.5
func LoadModules() []string
func MiddleCache ¶ added in v1.1.5
func MiddleCache(handle gin.HandlerFunc) gin.HandlerFunc
func MiddleWareAuth ¶
func MiddleWareAuth() gin.HandlerFunc
MiddleWareAuth 前置用户校验 只有部分API需要校验 需要校验的接口组,单独使用此中间件
func MiddleWareCors ¶
func MiddleWareCors() gin.HandlerFunc
func MiddlewareNoMethod ¶
func MiddlewareNoMethod() gin.HandlerFunc
func MiddlewareNoRoute ¶
func MiddlewareNoRoute() gin.HandlerFunc
func RegisterSignals ¶
RegisterSignals 监听部分信号使用
Types ¶
type Engine ¶
type Engine struct {
Config *EngineConfig
MiddleWare []gin.HandlerFunc
EnablePlnack bool
HeaderMap map[string]string
// contains filtered or unexported fields
}
Engine 一个包含gin和plnack的引擎
func NewEngine ¶
func NewEngine(cf *EngineConfig) *Engine
func (*Engine) Group ¶
func (e *Engine) Group(r string, ware ...gin.HandlerFunc) *gin.RouterGroup
Group 生成路由分组
func (*Engine) Handle ¶
func (e *Engine) Handle(method, r string, handler ...gin.HandlerFunc)
Handle 路由控制
func (*Engine) LoadMiddleWare ¶
func (e *Engine) LoadMiddleWare(m []gin.HandlerFunc)
LoadMiddleWare 加载中间件
func (*Engine) RunServerTLS ¶
func (*Engine) SetHeadersMap ¶
SetHeadersMap 设置请求头
type EngineConfig ¶
type MiddleWareConfig ¶
type MiddleWareConfig struct {
Name string `json:"name"`
Mode string `json:"mode"`
Active bool `json:"active"`
Urls []string `json:"urls"`
}
func LoadMiddleWareConfig ¶
func LoadMiddleWareConfig() []MiddleWareConfig
LoadMiddleWareConfig 同步的加载配置
type Module ¶ added in v1.1.7
func GetModules ¶ added in v1.1.7
func GetModules() []Module
type RouterGroup ¶
type RouterGroup gin.RouterGroup
Click to show internal directories.
Click to hide internal directories.