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 InitDb()
- func InitRedis()
- 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 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 Error
- type Gf
- func (gf *Gf) GetCache(name string) ICache
- func (gf *Gf) GetDb(name string) *gorm.DB
- func (gf *Gf) GetDefaultCache() ICache
- func (gf *Gf) GetDefaultDb() *gorm.DB
- func (gf *Gf) GetDefaultRedis() *redis.Client
- func (gf *Gf) GetRedis(name string) *redis.Client
- func (gf *Gf) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
- func (gf *Gf) Handle(httpMethod, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes
- func (gf *Gf) Use(middleware ...gin.HandlerFunc) gin.IRoutes
- 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 = "200" FailInternal = "400" FailCode = "500" CodeParamError = "400001" )
View Source
const (
DEFAULT = "default"
)
Variables ¶
View Source
var CodeMapping = codeMapping{ FailCode: "操作失败", FailInternal: "网络错误", SuccessCode: "操作成功", CodeParamError: "参数错误", }
View Source
var ResponseDataNil = struct {
}{}
View Source
var ServiceName string
Functions ¶
func InitConfig ¶
func InitConfig(path string)
func ResponseJson ¶
func ResponseJson(c *Context, data interface{})
func ResponseStr ¶
func RunWithRequest ¶
alias name, If run it, do not use RunProcess
Types ¶
type Context ¶
func GetContext ¶
type Controller ¶
type Controller struct {
TrackId string
Ctx *Context
Code string
Data interface{}
Req interface{}
// middleware functions
Middleware []ProcessFunc
// logic functions
ProcessFun ProcessFunc
// contains filtered or unexported fields
}
func GetNewController ¶
func GetNewController(g *gin.Context, req interface{}) *Controller
func (*Controller) Param ¶
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 ¶
func (controller *Controller) Query(key string) string
query things with gin
func (*Controller) Use ¶
func (controller *Controller) Use(fn func(controller *Controller) IError)
type Error ¶
func NewErrorStr ¶
type Gf ¶
type Gf struct {
Gin *gin.Engine
Log log.Logger
Config *goconfig.ConfigFile
Db map[string]*gorm.DB
Redis map[string]*redis.Client
Cache map[string]ICache
}
func (*Gf) GetDefaultCache ¶
get default cache, if config set MYSQL_DSN
func (*Gf) GetDefaultDb ¶
get default db, if config set MYSQL_DSN
func (*Gf) Group ¶
func (gf *Gf) Group(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup
alias gin group
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.