Documentation ¶
Index ¶
- Constants
- Variables
- func GetConfig() *goconfig.ConfigFile
- func GetDb(name string) *gorm.DB
- func GetGin() *gin.Engine
- func GetLog() log.Logger
- func InitConfig(path string)
- func ResponseJson(c *Context, data interface{})
- func ResponseStr(c *Context, str string)
- func RunProcess(controller IController, g *gin.Context)
- func RunWithRequest(req interface{}, g *gin.Context)
- type CodeMapping
- type Context
- type Controller
- func (controller *Controller) Decode() IError
- func (controller *Controller) GetContext() *Context
- func (controller *Controller) GetTrackId() string
- func (controller *Controller) Param(key string) string
- func (controller *Controller) Process() IError
- func (controller *Controller) Query(key string) string
- func (controller *Controller) SetContext(c *Context)
- func (controller *Controller) SetError(err IError)
- func (controller *Controller) SetTrackId(id string)
- func (controller *Controller) Use(fn func(controller *Controller) IError)
- type Core
- func (gG *Core) GetCache(name string) ICache
- func (gG *Core) GetDb(name string) *gorm.DB
- func (gG *Core) GetDefaultCache() ICache
- func (gG *Core) GetDefaultDb() *gorm.DB
- func (gG *Core) GetDefaultRedis() *redis.Client
- func (gG *Core) GetRedis(name string) *redis.Client
- func (gG *Core) GetSessionType() string
- func (gG *Core) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
- func (gG *Core) Handle(httpMethod, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes
- func (gG *Core) SetLoggerFormat(format string)
- func (gG *Core) Use(middleware ...gin.HandlerFunc) gin.IRoutes
- type Error
- type ICache
- type IController
- type IError
- type IGetterSetter
- type IModel
- type IModelStruct
- type IResponse
- type IRouter
- type ProcessFunc
- type Response
Constants ¶
View Source
const ( SuccessCode = "000000" FailCode = "500" FailUnknownCode = "-1" FailJsonParse = "-2" FailThirdLogin = "-3" FailSecret = "-4" FailParamsError = "-5" FailPostMax = "-6" FailInternal = "400" )
Variables ¶
View Source
var DefaultCodeMapping = CodeMapping{ FailCode: "操作失败", FailUnknownCode: "未知接口", FailJsonParse: "JSON解析错误或者接口不存在", FailThirdLogin: "第三方登录异常", FailSecret: "加密参数错误", SuccessCode: "操作成功", FailInternal: "内部错误", FailParamsError: "参数不合法", FailPostMax: "数据超过限制的大小", }
View Source
var ResponseDataNil = struct {
}{}
View Source
var ServiceName string
Functions ¶
func InitConfig ¶
func InitConfig(path string)
func ResponseJson ¶ added in v1.10.2
func ResponseJson(c *Context, data interface{})
func ResponseStr ¶ added in v1.10.2
func RunWithRequest ¶ added in v1.1.7
alias name, If run it, do not use RunProcess
Types ¶
type CodeMapping ¶
func (CodeMapping) AddCodeInfo ¶ added in v1.10.2
func (cm CodeMapping) AddCodeInfo(code, msg string)
func (CodeMapping) GetCodeInfo ¶
func (cm CodeMapping) GetCodeInfo(code string) string
type Context ¶
func GetContext ¶
type Controller ¶
type Controller struct { //log trackId TrackId string //访问id //the gin context Ctx *Context //response code, default success Code string //response data Data interface{} //output from data raw data parse Req interface{} //input params // middleware functions Middleware []ProcessFunc // logic functions ProcessFun ProcessFunc // contains filtered or unexported fields }
func GetNewController ¶ added in v1.1.4
func GetNewController(g *gin.Context, req interface{}) *Controller
get new Controller demo:
c := GetNewController(g, &UserInfo{UserId:1}) c.ProcessFunc = func(con *Controller) IError { u := con.Req.(*Req) con.Data = u }
func (*Controller) Param ¶ added in v1.1.4
func (controller *Controller) Param(key string) string
router params with gin
func (*Controller) Process ¶
func (controller *Controller) Process() IError
controller default Process
func (*Controller) Query ¶ added in v1.1.4
func (controller *Controller) Query(key string) string
query things with gin
func (*Controller) Use ¶ added in v1.1.4
func (controller *Controller) Use(fn func(controller *Controller) IError)
type Core ¶
type Core struct { Gin *gin.Engine Log log.Logger Config *goconfig.ConfigFile Db map[string]*gorm.DB Redis map[string]*redis.Client Cache map[string]ICache SessionType string }
func (*Core) GetDefaultCache ¶
get default cache, if config set MYSQL_DSN
func (*Core) GetDefaultDb ¶
get default db, if config set MYSQL_DSN
func (*Core) Group ¶
func (gG *Core) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
alias gin group
func (*Core) SetLoggerFormat ¶
set logger format params: %A - Time (2006-01-02T15:04:05.000Z) means all %T - Time (15:04:05 MST) %t - Time (15:04) %D - Date (2006/01/02) %d - Date (01/02/06) %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) %S - Source %M - Message Ignores unknown formats Recommended: "[%A] [%L] (%S) %M"
type ICache ¶
type ICache interface { GetBytes(key string) []byte GetString(key string) string GetMap(key string) map[string]string GetList(key string) []string GetValue(key string) (string, error) SetValue(key string, val interface{}, ex time.Duration) error SetList(key string, val ...interface{}) error SetString(key, val string, ex time.Duration) error SetMap(key string, m map[string]string, ex time.Duration) error SetBytes(key string, b []byte, ex time.Duration) error Expire(key string, ex time.Duration) Command(args ...string) error }
type IController ¶
type IController interface { //set context(gin) SetContext(ctx *Context) //get context(gin) GetContext() *Context //self decode request obj //example: //get: ?a=b&c=d => struct{A:b string `url:"a"`,C:d string `url:"c"`} //post(json): {"a":"b","c":"d"} struct{A:b string `url:"a"`,C:d string `url:"c"`} Decode() IError // processing business Process() IError //defer set error SetError(err IError) // Used to track distributed service link logs // recommend set it in query string GetTrackId() string // set trackId SetTrackId(id string) // contains filtered or unexported methods }
It's a controller with a request process
type IGetterSetter ¶
type IGetterSetter interface { GetAttribute(key string) interface{} SetAttribute(key string, value interface{}) bool SetAttributes(mp map[string]interface{}) bool GetAttributes() map[string]interface{} GetAttrInt(key string) (int, error) GetAttrInt64(key string) (int64, error) GetAttrFloat(key string) (float32, error) GetAttrFloat64(key string) (float64, error) GetAttrUInt(key string) (uint, error) GetAttrUInt64(key string) (uint64, error) GetAttrBool(key string) (bool, error) GetAttrString(key string) (string, error) GetAttrTime(key string) (time.Time, error) }
type IModelStruct ¶
type ProcessFunc ¶
type ProcessFunc func(controller *Controller) IError
Click to show internal directories.
Click to hide internal directories.