Documentation ¶
Index ¶
- Constants
- Variables
- func OpenMssql(charset string) error
- func OpenMySQL(charset string, sessions ...string) error
- func OpenRedis() error
- func RegisterFieldValidator(tag string, valfunc validator.Func)
- func RegisterValidators(valmap map[string]validator.Func)
- type AuthHandlerFunc
- type FormatCallback
- type NextFunc
- type NextFunc2
- type NextFunc3
- type RoleHandlerFunc
- type ScanCallback
- type TransactionCallback
- type WAuthController
- func (c *WAuthController) AuthRequestHeader(hidelog ...bool) string
- func (c *WAuthController) DoAfterAuthUnmarshal(ps any, nextFunc3 NextFunc3, fs ...bool)
- func (c *WAuthController) DoAfterAuthUnmarshalXml(ps any, nextFunc3 NextFunc3, fs ...bool)
- func (c *WAuthController) DoAfterAuthValidated(ps any, nextFunc3 NextFunc3, fs ...bool)
- func (c *WAuthController) DoAfterAuthValidatedXml(ps any, nextFunc3 NextFunc3, fs ...bool)
- func (c *WAuthController) DoAfterUnmarshal(ps any, nextFunc2 NextFunc2, fs ...bool)
- func (c *WAuthController) DoAfterUnmarshalXml(ps any, nextFunc2 NextFunc2, fs ...bool)
- func (c *WAuthController) DoAfterValidated(ps any, nextFunc2 NextFunc2, fs ...bool)
- func (c *WAuthController) DoAfterValidatedXml(ps any, nextFunc2 NextFunc2, fs ...bool)
- type WingController
- func (c *WingController) BindValue(key string, dest any) error
- func (c *WingController) ClientFrom() string
- func (c *WingController) DoAfterUnmarshal(ps any, nextFunc NextFunc, fs ...bool)
- func (c *WingController) DoAfterUnmarshalXml(ps any, nextFunc NextFunc, fs ...bool)
- func (c *WingController) DoAfterValidated(ps any, nextFunc NextFunc, fs ...bool)
- func (c *WingController) DoAfterValidatedXml(ps any, nextFunc NextFunc, fs ...bool)
- func (c *WingController) E400Params(err ...string)
- func (c *WingController) E400Unmarshal(err ...string)
- func (c *WingController) E400Validate(ps any, err ...string)
- func (c *WingController) E401Unauthed(err ...string)
- func (c *WingController) E403Denind(err ...string)
- func (c *WingController) E404Exception(err ...string)
- func (c *WingController) E405Disabled(err ...string)
- func (c *WingController) E406Input(err ...string)
- func (c *WingController) E409Duplicate(err ...string)
- func (c *WingController) E410Gone(err ...string)
- func (c *WingController) E426UpgradeRequired(err ...string)
- func (c *WingController) ErrorState(state int, err ...string)
- func (c *WingController) ResponData(state int, data ...map[any]any)
- func (c *WingController) ResponExErr(errmsg invar.WExErr)
- func (c *WingController) ResponJSON(state int, data ...any)
- func (c *WingController) ResponJSONP(state int, data ...any)
- func (c *WingController) ResponOK(hidelog ...bool)
- func (c *WingController) ResponXML(state int, data ...any)
- func (c *WingController) ResponYAML(state int, data ...any)
- func (c *WingController) SilentJSON(state int, data ...any)
- func (c *WingController) SilentJSONP(state int, data ...any)
- func (c *WingController) SilentXML(state int, data ...any)
- func (c *WingController) SilentYAML(state int, data ...any)
- func (c *WingController) SlientData(state int, data ...map[any]any)
- func (c *WingController) UncheckJSON(state int, dataORerr ...any)
- func (c *WingController) UncheckJSONP(state int, dataORerr ...any)
- func (c *WingController) UncheckXML(state int, dataORerr ...any)
- func (c *WingController) UncheckYAML(state int, dataORerr ...any)
- type WingProvider
- func (w *WingProvider) Affected(result sql.Result) (int64, error)
- func (w *WingProvider) AppendLike(query, filed, keyword string, and ...bool) string
- func (w *WingProvider) Count(query string) (int, error)
- func (w *WingProvider) ExeAffected(query string, args ...any) (int64, error)
- func (w *WingProvider) Execute(query string, args ...any) error
- func (w *WingProvider) FormatSets(updates any) string
- func (w *WingProvider) Insert(query string, args ...any) (int64, error)
- func (w *WingProvider) IsEmpty(query string, args ...any) (bool, error)
- func (w *WingProvider) IsExist(query string, args ...any) (bool, error)
- func (w *WingProvider) MultiInsert(query string, cnt int, cb FormatCallback) error
- func (w *WingProvider) MultiTransaction(cbs ...TransactionCallback) error
- func (w *WingProvider) Query(query string, args ...any) (*sql.Rows, error)
- func (w *WingProvider) QueryArray(query string, cb ScanCallback, args ...any) error
- func (w *WingProvider) QueryOne(query string, cb ScanCallback, args ...any) error
- func (w *WingProvider) Stub() *sql.DB
- func (w *WingProvider) Transaction(query string, args ...any) error
- type WingRedisConn
- func (c *WingRedisConn) Append(key string, value any) int
- func (c *WingRedisConn) Delete(key string) bool
- func (c *WingRedisConn) Deletes(nskeys ...string) (int, error)
- func (c *WingRedisConn) Exist(key string) (bool, error)
- func (c *WingRedisConn) Exists(nskeys ...string) (int, error)
- func (c *WingRedisConn) Expire(key string, expire int64, option ...string) bool
- func (c *WingRedisConn) ExpireAt(key string, expire int64, option ...string) bool
- func (c *WingRedisConn) Get(key string) (string, error)
- func (c *WingRedisConn) GetBool(key string) (bool, error)
- func (c *WingRedisConn) GetBytes(key string) ([]byte, error)
- func (c *WingRedisConn) GetDeadlock() int64
- func (c *WingRedisConn) GetDel(key string) (string, error)
- func (c *WingRedisConn) GetDelBool(key string) (bool, error)
- func (c *WingRedisConn) GetDelBytes(key string) ([]byte, error)
- func (c *WingRedisConn) GetDelFloat64(key string) (float64, error)
- func (c *WingRedisConn) GetDelInt(key string) (int, error)
- func (c *WingRedisConn) GetDelInt64(key string) (int64, error)
- func (c *WingRedisConn) GetDelUint64(key string) (uint64, error)
- func (c *WingRedisConn) GetEx(key string, option string, expire int64) (string, error)
- func (c *WingRedisConn) GetExBool(key string, option string, expire int64) (bool, error)
- func (c *WingRedisConn) GetExBytes(key string, option string, expire int64) ([]byte, error)
- func (c *WingRedisConn) GetExFloat64(key string, option string, expire int64) (float64, error)
- func (c *WingRedisConn) GetExInt(key string, option string, expire int64) (int, error)
- func (c *WingRedisConn) GetExInt64(key string, option string, expire int64) (int64, error)
- func (c *WingRedisConn) GetExUint64(key string, option string, expire int64) (uint64, error)
- func (c *WingRedisConn) GetExpire(key string) (int64, error)
- func (c *WingRedisConn) GetExpireMs(key string) (int64, error)
- func (c *WingRedisConn) GetFloat64(key string) (float64, error)
- func (c *WingRedisConn) GetInt(key string) (int, error)
- func (c *WingRedisConn) GetInt64(key string) (int64, error)
- func (c *WingRedisConn) GetRange(key string, start, end int) (string, error)
- func (c *WingRedisConn) GetRedisPool() redis.Conn
- func (c *WingRedisConn) GetUint64(key string) (uint64, error)
- func (c *WingRedisConn) HGet(key string, field any) (string, error)
- func (c *WingRedisConn) HGetBool(key string, field any) (bool, error)
- func (c *WingRedisConn) HGetBytes(key string, field any) ([]byte, error)
- func (c *WingRedisConn) HGetFloat64(key string, field any) (float64, error)
- func (c *WingRedisConn) HGetInt(key string, field any) (int, error)
- func (c *WingRedisConn) HGetInt64(key string, field any) (int64, error)
- func (c *WingRedisConn) HGetUint64(key string, field any) (uint64, error)
- func (c *WingRedisConn) HSet(key string, field, value any) bool
- func (c *WingRedisConn) NsArrKeys(keys []string) []string
- func (c *WingRedisConn) NsKey(key string) string
- func (c *WingRedisConn) NsKeys(keys ...string) []string
- func (c *WingRedisConn) Persist(key string) bool
- func (c *WingRedisConn) ServerTime() (int64, int64)
- func (c *WingRedisConn) Set(key string, value any, options ...any) error
- func (c *WingRedisConn) SetDeadlock(dur int64)
- func (c *WingRedisConn) SetEx(key string, value any, expire int64) error
- func (c *WingRedisConn) SetNamespace(ns string)
- func (c *WingRedisConn) SetNx(key string, value any) (bool, error)
- func (c *WingRedisConn) SetPx(key string, value any, expire int64) error
- func (c *WingRedisConn) SetRange(key string, value any, offset int) int
- func (c *WingRedisConn) StrLength(key string) int
Constants ¶
const ( OptEX = "EX" // seconds -- Set the specified expire time, in seconds OptPX = "PX" // milliseconds -- Set the specified expire time, in milliseconds. OptEXAT = "EXAT" // timestamp-seconds -- Set the specified Unix time at which the key will expire, in seconds. OptPXAT = "PXAT" // timestamp-milliseconds -- Set the specified Unix time at which the key will expire, in milliseconds. OptNX = "NX" // Only set the key if it does not already exist. OptXX = "XX" // Only set the key if it already exist. OptKEEPTTL = "KEEPTTL" // Retain the time to live associated with the key, use for SET commond. ExpNX = "NX" // Set expiry only when the key has no expiry. ExpXX = "XX" // Set expiry only when the key has an existing expiry. ExpGT = "GT" // Set expiry only when the new expiry is greater than current one. ExpLT = "LT" // Set expiry only when the new expiry is less than current one. CusOptDel = "DELETE" // The custom option to delete redis key after get commond execute. )
The follow options may support by diffrent Redis version, get more info by link https://redis.io/commands webset.
Variables ¶
var Validator *validator.Validate
Validator use for verify the input params on struct level
Functions ¶
func OpenMssql ¶
OpenMssql connect mssql database and check ping result, the connections holded by mvc.MssqlHelper object, the charset maybe 'utf8' or 'utf8mb4' same as database set.
`NOTICE`
you must config database params in /conf/app.config file as:
---
#### Case 1 For connect on prod mode.
[mssql] host = "127.0.0.1" port = 1433 name = "sampledb" user = "sa" pwd = "123456" timeout = 600
#### Case 2 For connect on dev mode.
[mssql-dev] host = "127.0.0.1" port = 1433 name = "sampledb" user = "sa" pwd = "123456" timeout = 600
#### Case 3 For both dev and prod mode, you can config all of up cases.
func OpenMySQL ¶
OpenMySQL connect database and check ping result, the connection holded by mvc.WingHelper object if signle connect, or cached connections in connPool map if multiple connect and select same one by given sessions of input params. the datatable charset maybe 'utf8' or 'utf8mb4' same as database set.
`USAGE`
you must config database params in /conf/app.config file as follows
---
#### Case 1 : For signle connect on prod mode.
[mysql] host = "127.0.0.1:3306" name = "sampledb" user = "root" pwd = "123456"
#### Case 2 : For signle connect on dev mode.
[mysql-dev] host = "127.0.0.1:3306" name = "sampledb" user = "root" pwd = "123456"
#### Case 3 : For both dev and prod mode, you can config all of up cases.
#### Case 4 : For multi-connections to set custom session keywords.
[mysql-a] ... same as use Case 1. [mysql-a-dev] ... same as use Case 2. [mysql-x] ... same as use Case 1. [mysql-x-dev] ... same as use Case 2.
func OpenRedis ¶
func OpenRedis() error
OpenRedis connect redis database server and auth password, the connections holded by mvc.WingRedis object.
`NOTICE` :
you must config redis params in /conf/app.config file as:
---
#### Case 1 : For connect on prod mode.
[redis] host = "127.0.0.1:6379" pwd = "123456" namespace = "project_namespace" deadlock = 20
#### Case 2 : For connect on dev mode.
[redis-dev] host = "127.0.0.1:6379" pwd = "123456" namespace = "project_namespace" deadlock = 20
#### Case 3 : For both dev and prod mode, you can config all of up cases.
#### Case 4 : For connect on prod mode without namespace and use default lock time.
[redis] host = "127.0.0.1:6379" pwd = "123456"
---
The configs means as:
`host` - is the redis server host ip and port. `pwd` - is the redis server authenticate password. `namespace` - is the prefix string or store key. `deadlock` - is the max time of deadlock, in seconds.
func RegisterFieldValidator ¶
func RegisterFieldValidator(tag string, valfunc validator.Func)
RegisterFieldValidator register validators on struct field level
func RegisterValidators ¶
func RegisterValidators(valmap map[string]validator.Func)
RegisterValidators register struct field validators from given map
Types ¶
type AuthHandlerFunc ¶
AuthHandlerFunc auth request token from http header and returen account secures.
var GAuthHandlerFunc AuthHandlerFunc
Global handler function to auth token from http header
type FormatCallback ¶
FormatCallback format query value to string for MultiInsert().
type NextFunc2 ¶
NextFunc2 do action after input params validated, it decode token to get account uuid.
type NextFunc3 ¶
NextFunc3 do action after input params validated, it decode token to get account uuid and password.
type RoleHandlerFunc ¶
RoleHandlerFunc verify role access permission from account service.
var GRoleHandlerFunc RoleHandlerFunc
Global handler function to verify role from http header
type ScanCallback ¶
ScanCallback use for scan query result from rows
type TransactionCallback ¶
TransactionCallback transaction callback for MultiTransaction().
type WAuthController ¶
type WAuthController struct {
WingController
}
WAuthController the extend controller base on WingController to support auth account from http headers, the client caller must append two headers before post request if expect the controller method enable execute token authentication from header.
* Authoration : It must fixed keyword as WENGOLD-V1.1
* Token : Authenticate JWT token responsed by login success
* Location : Optional value of client indicator, global location
`USAGE` :
The validator register code of input params struct see WingController description, but the restful auth api of router method as follow usecase 1 and 2.
---
`controller.go`
// define custom controller using header auth function type AccController struct { mvc.WAuthController } func init() { mvc.GAuthHandlerFunc = func(token string) (string, string) { // decode and verify token string, than return indecated // account uuid and password. return "account uuid", "account password" } }
`USECASE 1. Auth account and Parse input params`
// @Description Restful api bind with /login on POST method // @Param Authoration header string true "WENGOLD-V1.1" // @Param Token header string true "Authentication token" // @Param data body types.Accout true "input param description" // @Success 200 {string} "response data description" // @router /login [post] func (c *AccController) AccLogin() { ps := &types.Accout{} c.DoAfterValidated(ps, func(uuid string) (int, any) { // Or get authed account password as : // c.DoAfterAuthValidated(ps, func(uuid, pwd string) (int, any) { // do same business with input NO-EMPTY account uuid, // directe use c and ps param in this methed. // ... return http.StatusOK, "Done business" } , false /* not limit error message even code is 40x */) }
`USECASE 2. Auth account on GET http method`
// @Description Restful api bind with /detail on GET method // @Param Authoration header string true "WENGOLD-V1.1" // @Param Token header string true "Authentication token" // @Success 200 {types.Detail} "response data description" // @router /detail [get] func (c *AccController) AccDetail() { if uuid := c.AuthRequestHeader(); uuid != "" { // use c.BindValue("fieldkey", out) parse params from url c.ResponJSON(service.AccDetail(uuid)) } }
`USECASE 3. No-Auth and Use WingController`
// @Description Restful api bind with /update on POST method // @Param data body types.UserInfo true "input param description" // @Success 200 // @router /update [post] func (c *AccController) AccUpdate() { ps := &types.UserInfo{} c.WingController.DoAfterValidated(ps, func() (int, any) { // directe use c and ps param in this methed. // ... return http.StatusOK, nil } , false /* not limit error message even code is 40x */) }
`USECASE 4. No-Auth and Custom code`
// @Description Restful api bind with /list on GET method // @Success 200 {object} []types.Account "response data description" // @router /list [get] func (c *AccController) AccList() { // do same business without auth and input params c.ResponJSON(service.AccList()) }
func (*WAuthController) AuthRequestHeader ¶
func (c *WAuthController) AuthRequestHeader(hidelog ...bool) string
Get authoration and token from http header, than verify it and return account secures.
@Return 401, 403, 405, 426 codes returned on error.
func (*WAuthController) DoAfterAuthUnmarshal ¶
func (c *WAuthController) DoAfterAuthUnmarshal(ps any, nextFunc3 NextFunc3, fs ...bool)
DoAfterAuthUnmarshal do bussiness action after success unmarshaled the given json data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterAuthUnmarshalXml ¶
func (c *WAuthController) DoAfterAuthUnmarshalXml(ps any, nextFunc3 NextFunc3, fs ...bool)
DoAfterAuthUnmarshalXml do bussiness action after success unmarshaled the given xml data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterAuthValidated ¶
func (c *WAuthController) DoAfterAuthValidated(ps any, nextFunc3 NextFunc3, fs ...bool)
DoAfterAuthValidated do bussiness action after success validate the given json data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterAuthValidatedXml ¶
func (c *WAuthController) DoAfterAuthValidatedXml(ps any, nextFunc3 NextFunc3, fs ...bool)
DoAfterAuthValidatedXml do bussiness action after success validate the given xml data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterUnmarshal ¶
func (c *WAuthController) DoAfterUnmarshal(ps any, nextFunc2 NextFunc2, fs ...bool)
DoAfterUnmarshal do bussiness action after success unmarshaled the given json data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterUnmarshalXml ¶
func (c *WAuthController) DoAfterUnmarshalXml(ps any, nextFunc2 NextFunc2, fs ...bool)
DoAfterUnmarshalXml do bussiness action after success unmarshaled the given xml data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterValidated ¶
func (c *WAuthController) DoAfterValidated(ps any, nextFunc2 NextFunc2, fs ...bool)
DoAfterValidated do bussiness action after success validate the given json data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
func (*WAuthController) DoAfterValidatedXml ¶
func (c *WAuthController) DoAfterValidatedXml(ps any, nextFunc2 NextFunc2, fs ...bool)
DoAfterValidatedXml do bussiness action after success validate the given xml data.
@Return 400, 401, 403, 404, 405, 426 codes returned on error.
type WingController ¶
type WingController struct {
beego.Controller
}
WingController the base controller to support bee http functions.
`USAGE` :
Notice that you should register the field level validator for the input data's struct, then use it in struct describetion label as validate target.
---
`types.go`
// define restful api router input param struct type struct Accout { Acc string `json:"acc" validate:"required,IsVaildUuid"` PWD string `json:"pwd" validate:"required_without"` Num int `json:"num"` } // define custom validator on struct field level func isVaildUuid(fl validator.FieldLevel) bool { m, _ := regexp.Compile("^[0-9a-zA-Z]*$") str := fl.Field().String() return m.MatchString(str) } func init() { // register router input params struct validators mvc.RegisterFieldValidator("IsVaildUuid", isVaildUuid) }
---
`controller.go`
// @Description Restful api bind with /login on POST method // @Param data body types.Accout true "input param description" // @Success 200 {string} "response data description" // @router /login [post] func (c *AccController) AccLogin() { ps := &types.Accout{} c.DoAfterValidated(ps, func() (int, any) { // do same business function // directe use c and ps param in this methed. // ... return http.StatusOK, "Done business" } , false /* not limit error message even code is 40x */) }
func (*WingController) BindValue ¶
func (c *WingController) BindValue(key string, dest any) error
BindValue bind value with key from url, the dest container must pointer
func (*WingController) ClientFrom ¶
func (c *WingController) ClientFrom() string
ClientFrom return client ip from who requested
func (*WingController) DoAfterUnmarshal ¶
func (c *WingController) DoAfterUnmarshal(ps any, nextFunc NextFunc, fs ...bool)
DoAfterUnmarshal do bussiness action after success unmarshaled the given json data.
@Return 400, 404 codes returned on error.
func (*WingController) DoAfterUnmarshalXml ¶
func (c *WingController) DoAfterUnmarshalXml(ps any, nextFunc NextFunc, fs ...bool)
DoAfterUnmarshalXml do bussiness action after success unmarshaled the given xml data.
@Return 400, 404 codes returned on error.
func (*WingController) DoAfterValidated ¶
func (c *WingController) DoAfterValidated(ps any, nextFunc NextFunc, fs ...bool)
DoAfterValidated do bussiness action after success validate the given json data.
@Return 400, 404 codes returned on error.
func (*WingController) DoAfterValidatedXml ¶
func (c *WingController) DoAfterValidatedXml(ps any, nextFunc NextFunc, fs ...bool)
DoAfterValidatedXml do bussiness action after success validate the given xml data.
@Return 400, 404 codes returned on error.
func (*WingController) E400Params ¶
func (c *WingController) E400Params(err ...string)
E400Params response 400 invalid params error state to client
func (*WingController) E400Unmarshal ¶
func (c *WingController) E400Unmarshal(err ...string)
E400rUnmarshal response 400 unmarshal params error state to client
func (*WingController) E400Validate ¶
func (c *WingController) E400Validate(ps any, err ...string)
E400Validate response 400 invalid params error state to client, then print the params data and validate error
func (*WingController) E401Unauthed ¶
func (c *WingController) E401Unauthed(err ...string)
E401Unauthed response 401 unauthenticated error state to client
func (*WingController) E403Denind ¶
func (c *WingController) E403Denind(err ...string)
E403Denind response 403 permission denind error state to client
func (*WingController) E404Exception ¶
func (c *WingController) E404Exception(err ...string)
E404Exception response 404 not found error state to client
func (*WingController) E405Disabled ¶
func (c *WingController) E405Disabled(err ...string)
E405Disabled response 405 function disabled error state to client
func (*WingController) E406Input ¶
func (c *WingController) E406Input(err ...string)
E406Input response 406 invalid inputs error state to client
func (*WingController) E409Duplicate ¶
func (c *WingController) E409Duplicate(err ...string)
E409Duplicate response 409 duplicate error state to client
func (*WingController) E410Gone ¶
func (c *WingController) E410Gone(err ...string)
E410Gone response 410 gone error state to client
func (*WingController) E426UpgradeRequired ¶
func (c *WingController) E426UpgradeRequired(err ...string)
E426UpgradeRequired response 426 upgrade required error state to client
func (*WingController) ErrorState ¶
func (c *WingController) ErrorState(state int, err ...string)
ErrorState response error state to client
func (*WingController) ResponData ¶
func (c *WingController) ResponData(state int, data ...map[any]any)
ResponData sends JSON, JSONP, XML, YAML response datas to client, the data type depending on the value of the Accept header.
func (*WingController) ResponExErr ¶
func (c *WingController) ResponExErr(errmsg invar.WExErr)
ResponExErr sends a extend error as response data on 202 status code
func (*WingController) ResponJSON ¶
func (c *WingController) ResponJSON(state int, data ...any)
ResponJSON sends a json response to client on status check mode.
func (*WingController) ResponJSONP ¶
func (c *WingController) ResponJSONP(state int, data ...any)
ResponJSONP sends a jsonp response to client on status check mode.
func (*WingController) ResponOK ¶
func (c *WingController) ResponOK(hidelog ...bool)
ResponOK sends a empty success response to client
func (*WingController) ResponXML ¶
func (c *WingController) ResponXML(state int, data ...any)
ResponXML sends xml response to client on status check mode.
func (*WingController) ResponYAML ¶
func (c *WingController) ResponYAML(state int, data ...any)
ResponYAML sends yaml response to client on status check mode.
func (*WingController) SilentJSON ¶
func (c *WingController) SilentJSON(state int, data ...any)
SilentJSON sends a json response to client without output ok log.
func (*WingController) SilentJSONP ¶
func (c *WingController) SilentJSONP(state int, data ...any)
SilentJSONP sends a jsonp response to client without output ok log.
func (*WingController) SilentXML ¶
func (c *WingController) SilentXML(state int, data ...any)
SilentXML sends xml response to client without output ok log.
func (*WingController) SilentYAML ¶
func (c *WingController) SilentYAML(state int, data ...any)
SilentYAML sends yaml response to client without output ok log.
func (*WingController) SlientData ¶
func (c *WingController) SlientData(state int, data ...map[any]any)
SlientData sends JSON, JSONNP, XML, YAML, response data to client without output ok log.
func (*WingController) UncheckJSON ¶
func (c *WingController) UncheckJSON(state int, dataORerr ...any)
UncheckJSON sends a json response to client witchout status check.
func (*WingController) UncheckJSONP ¶
func (c *WingController) UncheckJSONP(state int, dataORerr ...any)
UncheckJSONP sends a jsonp response to client witchout status check.
func (*WingController) UncheckXML ¶
func (c *WingController) UncheckXML(state int, dataORerr ...any)
UncheckXML sends xml response to client witchout status check.
func (*WingController) UncheckYAML ¶
func (c *WingController) UncheckYAML(state int, dataORerr ...any)
UncheckYAML sends yaml response to client witchout status check.
type WingProvider ¶
WingProvider content provider to support database utils
var MssqlHelper *WingProvider
MssqlHelper content provider to hold mssql database connections, it will nil before mvc.OpenMssql() called.
var ( // WingHelper content provider to hold database connections, // it will nil before mvc.OpenMySQL() called. WingHelper *WingProvider )
func Select ¶
func Select(session string) *WingProvider
Select mysql Connection by request key words if mode is dev, the key will auto splice '-dev'
func (*WingProvider) Affected ¶
func (w *WingProvider) Affected(result sql.Result) (int64, error)
Affected append page limitation end of sql string
func (*WingProvider) AppendLike ¶
func (w *WingProvider) AppendLike(query, filed, keyword string, and ...bool) string
AppendLike append like keyword end of sql string, DON'T call it when exist limit key in sql string
func (*WingProvider) Count ¶
func (w *WingProvider) Count(query string) (int, error)
Count call sql.Query() to count results
func (*WingProvider) ExeAffected ¶
func (w *WingProvider) ExeAffected(query string, args ...any) (int64, error)
ExeAffected call sql.Prepare() and stmt.Exec() to update or delete records
func (*WingProvider) Execute ¶
func (w *WingProvider) Execute(query string, args ...any) error
Execute call sql.Prepare() and stmt.Exec() to update or delete records
func (*WingProvider) FormatSets ¶
func (w *WingProvider) FormatSets(updates any) string
FormatSets format update sets for sql update
---
sets := w.FormatSets(struct { StringFiled string EmptyString string BlankString string TrimString string IntFiled int I32Filed int32 I64Filed int64 F32Filed float32 F64Filed float64 BoolFiled bool }{"string", "", " ", " trim ", 123, 32, 64, 32.123, 64.123, true}) // sets: stringfiled='string', trimstring='trim', intfiled=123, i32filed=32, i64filed=64, f32filed=32.123, f64filed=64.123, boolfiled=true logger.I("sets:", sets)
func (*WingProvider) Insert ¶
func (w *WingProvider) Insert(query string, args ...any) (int64, error)
Insert call sql.Prepare() and stmt.Exec() to insert a new record.
`@see` Use MultiInsert() to insert multiple values in once database operation.
func (*WingProvider) IsEmpty ¶
func (w *WingProvider) IsEmpty(query string, args ...any) (bool, error)
IsEmpty call sql.Query() to check target data if empty
func (*WingProvider) IsExist ¶
func (w *WingProvider) IsExist(query string, args ...any) (bool, error)
IsExist call sql.Query() to check target data if exist
func (*WingProvider) MultiInsert ¶
func (w *WingProvider) MultiInsert(query string, cnt int, cb FormatCallback) error
MultiInsert format and combine multiple values to insert at once, this method can provide high-performance than call Insert() one by one.
---
query := "INSERT sametable (field1, field2, fieldn) VALUES" err := mvc.MultiInsert(query, 5, func(index int) string { return fmt.Sprintf("(%v, %v, %v)", v1, v2, v3) // For string values like follows: // return fmt.Sprintf("(\"%s\", \"%s\", \"%s\")", v1, v2, v3) })
func (*WingProvider) MultiTransaction ¶
func (w *WingProvider) MultiTransaction(cbs ...TransactionCallback) error
MultiTransaction excute multiple transactions, it will rollback all operations when case error.
---
// Excute 3 transactions in callback with different query1 ~ 3 err := mvc.MultiTransaction( func(tx *sql.Tx) (sql.Result, error) { return tx.Exec(query1, args...) }, func(tx *sql.Tx) (sql.Result, error) { return tx.Exec(query2, args...) }, func(tx *sql.Tx) (sql.Result, error) { return tx.Exec(query3, args...) })
func (*WingProvider) QueryArray ¶
func (w *WingProvider) QueryArray(query string, cb ScanCallback, args ...any) error
QueryArray call sql.Query() to query multi records
func (*WingProvider) QueryOne ¶
func (w *WingProvider) QueryOne(query string, cb ScanCallback, args ...any) error
QueryOne call sql.Query() to query one record
func (*WingProvider) Stub ¶
func (w *WingProvider) Stub() *sql.DB
Stub return content provider connection
func (*WingProvider) Transaction ¶
func (w *WingProvider) Transaction(query string, args ...any) error
Transaction execute one sql transaction, it will rollback when operate failed.
`@see` Use MultiTransaction() to excute multiple transaction as once.
type WingRedisConn ¶
type WingRedisConn struct {
// contains filtered or unexported fields
}
WingRedisConn content provider to support redis utils
var WingRedis *WingRedisConn
WingRedis a connecter to access redis database data, it will nil before mvc.OpenRedis() called
func (*WingRedisConn) Append ¶
func (c *WingRedisConn) Append(key string, value any) int
Append append a value of a key, it will transform the given value to string first, than append end of exist string, or set value same as SET commond.
func (*WingRedisConn) Delete ¶
func (c *WingRedisConn) Delete(key string) bool
Delete delete a key, see Deletes.
func (*WingRedisConn) Deletes ¶
func (c *WingRedisConn) Deletes(nskeys ...string) (int, error)
Deletes delete the given keys, and return deleted keys count. you can use NsKey() or Nskeys() to transform origin keys to namespaced keys, and then call Deletes(nskeys[0], nskeys[1] ... nskeys[m]) to multiple delete.
func (*WingRedisConn) Exist ¶
func (c *WingRedisConn) Exist(key string) (bool, error)
Exist determine if a key exists, only support one key one check, set Exists.
func (*WingRedisConn) Exists ¶
func (c *WingRedisConn) Exists(nskeys ...string) (int, error)
Exists determine if given keys exist, and return exist keys count, you can use NsKey() or Nskeys() to transform origin keys to namespaced keys, and then call Exists(nskeys[0], nskeys[1] ... nskeys[m]) to multiple check.
func (*WingRedisConn) Expire ¶
func (c *WingRedisConn) Expire(key string, expire int64, option ...string) bool
Expire set a key's time to live in seconds, the optional values can be set as ExpNX, ExpXX, ExpGT, ExpLT since Redis 7.0 support.
func (*WingRedisConn) ExpireAt ¶
func (c *WingRedisConn) ExpireAt(key string, expire int64, option ...string) bool
ExpireAt set the expiration for a key as a unix timestamp in seconds, the optional values can be set as ExpNX, ExpXX, ExpGT, ExpLT since Redis 7.0 support.
func (*WingRedisConn) Get ¶
func (c *WingRedisConn) Get(key string) (string, error)
Get get the string value of key.
func (*WingRedisConn) GetBool ¶
func (c *WingRedisConn) GetBool(key string) (bool, error)
GetBool get the bool value of key.
func (*WingRedisConn) GetBytes ¶
func (c *WingRedisConn) GetBytes(key string) ([]byte, error)
GetBytes get the bytes array of key.
func (*WingRedisConn) GetDeadlock ¶
func (c *WingRedisConn) GetDeadlock() int64
GetDeadlock get the max deadlock duration
func (*WingRedisConn) GetDel ¶
func (c *WingRedisConn) GetDel(key string) (string, error)
GetDel get and delete the string value of key
func (*WingRedisConn) GetDelBool ¶
func (c *WingRedisConn) GetDelBool(key string) (bool, error)
GetDelBool get and delete the bool value of key, see Pull.
func (*WingRedisConn) GetDelBytes ¶
func (c *WingRedisConn) GetDelBytes(key string) ([]byte, error)
GetDelBytes get and delete the bytes array of key, see Pull.
func (*WingRedisConn) GetDelFloat64 ¶
func (c *WingRedisConn) GetDelFloat64(key string) (float64, error)
GetDelFloat64 get and delete the float value of key, see Pull.
func (*WingRedisConn) GetDelInt ¶
func (c *WingRedisConn) GetDelInt(key string) (int, error)
GetDelInt get and delete the int value of key.
func (*WingRedisConn) GetDelInt64 ¶
func (c *WingRedisConn) GetDelInt64(key string) (int64, error)
GetDelInt64 get and delete the int64 value of key.
func (*WingRedisConn) GetDelUint64 ¶
func (c *WingRedisConn) GetDelUint64(key string) (uint64, error)
GetDelUint64 get and delete the uint64 value of key.
func (*WingRedisConn) GetEx ¶
GETEX get the string value of a key and optionally set its expiration.
func (*WingRedisConn) GetExBool ¶
GetExBool get the bool value of key and optionally set its expiration.
func (*WingRedisConn) GetExBytes ¶
GetExBytes get the bytes array of key and optionally set its expiration.
func (*WingRedisConn) GetExFloat64 ¶
GetExFloat64 get the float value of key and optionally set its expiration.
func (*WingRedisConn) GetExInt ¶
GetExInt get the int value of key and optionally set its expiration.
func (*WingRedisConn) GetExInt64 ¶
GetExInt64 get the int64 value of key and optionally set its expiration.
func (*WingRedisConn) GetExUint64 ¶
GetExUint64 get the uint64 value of key and optionally set its expiration.
func (*WingRedisConn) GetExpire ¶
func (c *WingRedisConn) GetExpire(key string) (int64, error)
GetExpire get the time to live for a key in secons.
func (*WingRedisConn) GetExpireMs ¶
func (c *WingRedisConn) GetExpireMs(key string) (int64, error)
GetExpireMs get the time to live for a key in milliseconds.
func (*WingRedisConn) GetFloat64 ¶
func (c *WingRedisConn) GetFloat64(key string) (float64, error)
GetFloat64 get the float value of key.
func (*WingRedisConn) GetInt ¶
func (c *WingRedisConn) GetInt(key string) (int, error)
GetInt get the int value of key.
func (*WingRedisConn) GetInt64 ¶
func (c *WingRedisConn) GetInt64(key string) (int64, error)
GetInt64 get the int64 value of key.
func (*WingRedisConn) GetRange ¶
func (c *WingRedisConn) GetRange(key string, start, end int) (string, error)
GetRange get the string value of key cut by given range.
func (*WingRedisConn) GetRedisPool ¶
func (c *WingRedisConn) GetRedisPool() redis.Conn
GetRedisPool get redis pool
func (*WingRedisConn) GetUint64 ¶
func (c *WingRedisConn) GetUint64(key string) (uint64, error)
GetUint64 get the uint64 value of key.
func (*WingRedisConn) HGet ¶
func (c *WingRedisConn) HGet(key string, field any) (string, error)
HGet get the string value of a hash field.
func (*WingRedisConn) HGetBool ¶
func (c *WingRedisConn) HGetBool(key string, field any) (bool, error)
HGetBool get the bool value of a hash field.
func (*WingRedisConn) HGetBytes ¶
func (c *WingRedisConn) HGetBytes(key string, field any) ([]byte, error)
HGetBytes get the bytes array of a hash field.
func (*WingRedisConn) HGetFloat64 ¶
func (c *WingRedisConn) HGetFloat64(key string, field any) (float64, error)
HGetFloat64 get the float value of a hash field.
func (*WingRedisConn) HGetInt ¶
func (c *WingRedisConn) HGetInt(key string, field any) (int, error)
HGetInt get the int value of a hash field.
func (*WingRedisConn) HGetInt64 ¶
func (c *WingRedisConn) HGetInt64(key string, field any) (int64, error)
HGetInt64 get the int64 value of a hash field.
func (*WingRedisConn) HGetUint64 ¶
func (c *WingRedisConn) HGetUint64(key string, field any) (uint64, error)
HGetUint64 get the uint64 value of a hash field.
func (*WingRedisConn) HSet ¶
func (c *WingRedisConn) HSet(key string, field, value any) bool
HSet set the string value of a hash field.
func (*WingRedisConn) NsArrKeys ¶
func (c *WingRedisConn) NsArrKeys(keys []string) []string
NsArrKeys transform origin keys to namespaced keys
func (*WingRedisConn) NsKey ¶
func (c *WingRedisConn) NsKey(key string) string
NsKey transform origin key to namespaced key
func (*WingRedisConn) NsKeys ¶
func (c *WingRedisConn) NsKeys(keys ...string) []string
NsKeys transform origin keys to namespaced keys
func (*WingRedisConn) Persist ¶
func (c *WingRedisConn) Persist(key string) bool
Persist remove the expiration from a key.
func (*WingRedisConn) ServerTime ¶
func (c *WingRedisConn) ServerTime() (int64, int64)
ServerTime get redis server unix time is seconds and microsecodns.
see command time(https://redis.io/commands/time)
func (*WingRedisConn) Set ¶
func (c *WingRedisConn) Set(key string, value any, options ...any) error
Set set a value of a key.
option[0] : OptEX, OptPX, OptEXAT, OptPXAT, OptNX, OptXX, OptKEEPTTL option[1] : time number in seconds, milliseconds, or unix timestampe
---
err := c.Set("foo1", 123456) err := c.Set("foo2", 123456, OptEX, 60 * 10) err := c.Set("foo3", 56.789, OptPX, 1000000) err := c.Set("foo4", "5678", OptEXAT, 1628778035) err := c.Set("foo5", true, OptPXAT, 1628778035) err := c.Set("foo6", 111333, OptNX) err := c.Set("foo7", 222444, OptXX) err := c.Set("foo8", 333555, OptKEEPTTL)
func (*WingRedisConn) SetDeadlock ¶
func (c *WingRedisConn) SetDeadlock(dur int64)
SetDeadlock set the max deadlock duration
func (*WingRedisConn) SetEx ¶
func (c *WingRedisConn) SetEx(key string, value any, expire int64) error
SetEx set a value and expiration in seconds of a key.
func (*WingRedisConn) SetNamespace ¶
func (c *WingRedisConn) SetNamespace(ns string)
SetNamespace set server uniqu namespace
func (*WingRedisConn) SetNx ¶
func (c *WingRedisConn) SetNx(key string, value any) (bool, error)
SetNx set a value of a unexist key, it return false when failed set on exist key.
func (*WingRedisConn) SetPx ¶
func (c *WingRedisConn) SetPx(key string, value any, expire int64) error
SetPx set a value and expiration in milliseconds of a key.
func (*WingRedisConn) SetRange ¶
func (c *WingRedisConn) SetRange(key string, value any, offset int) int
SetRange overwrite part of a string at key starting at the specified offset, it will transform the given value to string first, and retuen the memery length.
func (*WingRedisConn) StrLength ¶
func (c *WingRedisConn) StrLength(key string) int
StrLength get the string value of key, it return 0 if the key unexist.