Documentation ¶
Index ¶
- Constants
- Variables
- func AddRouterGroups(rgs ...*RouterGroup)
- func AllowOriginFunc(f func(string) bool)
- func HandlerWrapper(controllerType reflect.Type, method string) gin.HandlerFunc
- func ParseRouter(rootDir ...string)
- func Serve()
- func Use(middleware ...MiddleWareHandler) gin.IRoutes
- type App
- type CommentRouter
- type Config
- type Context
- type Controller
- type ControllerCommentRouter
- type Cors
- type IController
- type Log
- type MiddleWareHandler
- type RouterGroup
- type Server
- type Wago
- type WrapperFunc
Constants ¶
const ( RUN_MODE_DEBUG = "debug" RUN_MODE_TEST = "test" RUN_MODE_RELEASE = "release" ROUTER_MODE_AUTO = "auto" ROUTER_MODE_COMMENT = "comment" // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... LevelPanic = logrus.PanicLevel // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. LevelFatal = logrus.FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. LevelError = logrus.ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. LevelWarn = logrus.WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. LevelInfo = logrus.InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. LevelDebug = logrus.DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. LevelTrace = logrus.TraceLevel )
const (
REQUEST_ID = "W-Request-Id"
)
Variables ¶
var ( CommentRouters = make(map[string][]CommentRouter) // HTTP_METHOD list the supported http methods. HTTP_METHOD = map[string]bool{ "GET": true, "POST": true, "PUT": true, "DELETE": true, "PATCH": true, "OPTIONS": true, "HEAD": true, "TRACE": true, "CONNECT": true, "MKCOL": true, "COPY": true, "MOVE": true, "PROPFIND": true, "PROPPATCH": true, "LOCK": true, "UNLOCK": true, } // while RouterMode = auto, don't register struct method to router EXCLUDE_ROUTER_METHOD = map[string]bool{ "Init": true, } )
var (
AppConfig = &Config{}
)
Functions ¶
func HandlerWrapper ¶
func HandlerWrapper(controllerType reflect.Type, method string) gin.HandlerFunc
HandlerWrapper is a wrapper to transform controller'method to gin.HandlerFunc @TODO catch exceptions while method not exist encapsulate controller's method in gin.HandlerFunc means: while gin.HandlerFunc is invoked, the target controller's method will be invoked
func Use ¶
func Use(middleware ...MiddleWareHandler) gin.IRoutes
Use attaches 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.
Types ¶
type App ¶
type App struct { App string RunMode string // router mode, [auto, comment] supported. RouterMode string // only when RouterMode=comment, ControllerPath is valid. ControllerPath string // only when RouterMode=auto, RouterSep is valid. // only ”(empty), '-' or '_' allowed. // ” means use struct/method name as router path, eg: /v1/HomeTest/HelloWorld // '-' means use snake string as router path, eg: /v1/home-test/hello-world // '_' means use snake string as router path, eg: /v1/home_test/hello_world RouterSep string }
application configuration
type CommentRouter ¶
type Controller ¶
type ControllerCommentRouter ¶
type ControllerCommentRouter struct { Pkg string // name of current controller's pkg name, e.g: package home, Pkg="home" Controller string CommentRouters []CommentRouter }
type Cors ¶
type Cors struct { AllowOrigins []string AllowMethods []string AllowHeaders []string ExposeHeaders []string AllowCredentials bool AllowOriginFunc func(string) bool MaxAge int }
HTTP CORS configuration
type IController ¶
type IController interface {
Init(*Context)
}
type Log ¶
type Log struct { // [json,text,logstash,fluentd] supported Formatter string // Log level Level uint32 // logging method name LogMethodName bool // Filename is the file to write logs to. Backup log files will be retained // in the same directory. It uses <processname>-lumberjack.log in // os.TempDir() if empty. Filename string // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int // Compress determines if the rotated log files should be compressed // using gzip. Compress bool // print log to console Console bool }
log configurations
type MiddleWareHandler ¶
type MiddleWareHandler = gin.HandlerFunc
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
add controller instance to set routers
func NewRouterGroup ¶
func NewRouterGroup() *RouterGroup
func (*RouterGroup) Controller ¶
func (t *RouterGroup) Controller(controllers ...IController) *RouterGroup
config controller routers
func (*RouterGroup) Prefix ¶
func (t *RouterGroup) Prefix(prefix string) *RouterGroup
set api prefixes
func (*RouterGroup) Use ¶
func (t *RouterGroup) Use(middleWares ...MiddleWareHandler) *RouterGroup
bind middleWares
type Server ¶
type Server struct { Port int Host string ReadTimeout int ReadHeaderTimeout int WhiteTimeout int IdleTimeout int MaxHeaderBytes int // HTTP CORS configuration Cors Cors }
TLSConfig *tls.Config TLSNextProto map[string]func(*Server, *tls.Conn, Handler) ConnState func(net.Conn, ConnState) HTTP server configuration
type Wago ¶
type Wago struct { // Use gin as http server Server *gin.Engine // contains filtered or unexported fields }
var (
WagoApp *Wago
)
type WrapperFunc ¶
type WrapperFunc func()
Wrapper for controller functions which is type of gin.HandlerFunc WagoHandler gin.HandlerFunc