Documentation
¶
Index ¶
- func GetMiddlewareKey(group, name string) string
- type HandlerManager
- func (m *HandlerManager) Get(name string) (handler.MiddlewareNewFunc, bool)
- func (m *HandlerManager) GetMiddleware(key string) (handler.Middleware, bool)
- func (m *HandlerManager) Register(name string, handler handler.MiddlewareNewFunc)
- func (m *HandlerManager) RegisterMiddleware(key string, mid handler.Middleware)
- func (m *HandlerManager) Shutdown(ctx context.Context) error
- type Option
- type Router
- type RouterGroup
- type Server
- func (s *Server) Apply(cfg *conf.Configuration) error
- func (s *Server) HandlerManager() *HandlerManager
- func (s *Server) ListenAndServe() (err error)
- func (s *Server) Router() *Router
- func (s *Server) Run() error
- func (s *Server) ServerOptions() ServerOptions
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Stop(ctx context.Context) error
- type ServerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMiddlewareKey ¶ added in v0.4.0
GetMiddlewareKey returns a unique key for middleware
Types ¶
type HandlerManager ¶ added in v0.4.0
type HandlerManager struct {
// contains filtered or unexported fields
}
HandlerManager is a manager about middleware new function and shutdown function, and auto calls those functions when needed; it tries to keep the middleware are immutable.
If you want to get middleware information in your application, and you know that your middleware is immutable, or you can control it, you can store it in the cache for reuse.
func NewHandlerManager ¶ added in v0.4.0
func NewHandlerManager() *HandlerManager
NewHandlerManager creates a new middleware manager, initialize common useful middlewares.
func (*HandlerManager) Get ¶ added in v0.4.0
func (m *HandlerManager) Get(name string) (handler.MiddlewareNewFunc, bool)
func (*HandlerManager) GetMiddleware ¶ added in v0.4.0
func (m *HandlerManager) GetMiddleware(key string) (handler.Middleware, bool)
GetMiddleware returns a middleware instance by key. Should not change the middleware's option value and keep middleware run immutable.
func (*HandlerManager) Register ¶ added in v0.4.0
func (m *HandlerManager) Register(name string, handler handler.MiddlewareNewFunc)
Register a middleware new function.
func (*HandlerManager) RegisterMiddleware ¶ added in v0.4.0
func (m *HandlerManager) RegisterMiddleware(key string, mid handler.Middleware)
RegisterMiddleware register a middleware instance. Should call it after Register. Keep the key unique.
type Option ¶
type Option func(s *ServerOptions)
Option the function to apply a configuration option
func WithConfiguration ¶ added in v0.1.0
func WithConfiguration(cfg *conf.Configuration) Option
WithConfiguration set up the configuration of the web server by a configuration instance
func WithGracefulStop ¶ added in v0.1.0
func WithGracefulStop() Option
WithGracefulStop indicate use graceful stop
func WithMiddlewareApplyFunc ¶ added in v0.4.0
func WithMiddlewareApplyFunc(name string, handlerFunc handler.MiddlewareApplyFunc) Option
WithMiddlewareApplyFunc provide a simple way to inject middleware by gin.HandlerFunc.
Notice: the middleware usual attach `c.Next()` or `c.Abort` to indicator whether exits the method. example:
RegisterMiddleware("test", func(cfg *conf.Configuration){ // use cfg to init return func(c *gin.Context) { // ....process c.Next() or c.Abort() or c.AbortWithStatus(500) } })
func WithMiddlewareNewFunc ¶ added in v0.4.0
func WithMiddlewareNewFunc(name string, newFunc handler.MiddlewareNewFunc) Option
WithMiddlewareNewFunc provide a simple way to inject middleware by MiddlewareNewFunc.
type Router ¶
type Router struct { *gin.Engine Groups []*RouterGroup // contains filtered or unexported fields }
Router is base on Gin.
func NewRouter ¶
func NewRouter(options *ServerOptions) *Router
func (*Router) Apply ¶
func (r *Router) Apply(cnf *conf.Configuration) (err error)
Apply implements the conf.Configurable interface.
RouterGroups and Middlewares must init by order, so we use array-type in configuration.
func (*Router) FindGroup ¶ added in v0.0.3
func (r *Router) FindGroup(basePath string) *RouterGroup
FindGroup return a specified router group by an url format base path.
parameter basePath is map to configuration:
routerGroups: - group: basePath: "/auth"
type RouterGroup ¶ added in v0.0.3
type RouterGroup struct { Group *gin.RouterGroup Router *Router // contains filtered or unexported fields }
RouterGroup is a wrapper for gin.RouterGroup.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Apply ¶
func (s *Server) Apply(cfg *conf.Configuration) error
Apply implement conf.Configuration
func (*Server) HandlerManager ¶ added in v0.0.3
func (s *Server) HandlerManager() *HandlerManager
HandlerManager return server's handler manager,it's convenient to process handler
func (*Server) ListenAndServe ¶ added in v0.0.3
ListenAndServe Starts Http Server
return
http.ErrServerClosed or other error
func (*Server) ServerOptions ¶ added in v0.0.3
func (s *Server) ServerOptions() ServerOptions
ServerOptions return a setting used by web server