Documentation ¶
Index ¶
- Constants
- Variables
- func AESCBCDecrypt(encryptData, key []byte) ([]byte, error)
- func AESCBCEncrypt(rawData, key []byte) ([]byte, error)
- func ASCIISort(data interface{}, includeEmpty bool, omitKeys ...[]string) (sortedKeys []string)
- func AddDefaultIntlMessage(messages map[string]string)
- func AddExtraSpaceIfExist(str string) string
- func AddJob(spec string, name string, cmd func(c *JobContext)) (cron.EntryID, error)
- func AddJobEntry(j *Job) error
- func AddPresetIntlMessage(messages map[string]map[string]string)
- func AddWhitelist(rules ...interface{})
- func AutoMigrate(values ...interface{}) *gorm.DB
- func Base64Decode(p string) (v string)
- func Base64Encode(p string) (v string)
- func Base64URLDecode(p string) (v string)
- func Base64URLEncode(p string) (v string)
- func BatchInsert(tx *gorm.DB, insertBase string, items []BatchInsertItem, batchSize int) error
- func BeforeUse(handlers ...HandlerFunc)
- func BeforeUseGin(handlers ...gin.HandlerFunc)
- func BuildKey(keys ...string) string
- func CORSMiddleware() gin.HandlerFunc
- func CompareHashAndPassword(hashedPassword, password string) error
- func ContainsCache(key string, limit int) (val map[string]string)
- func Copy(src interface{}, dest interface{}) (err error)
- func DB() *gorm.DB
- func DEBUG(v ...interface{})
- func DEBUGWithFields(fields logrus.Fields, v ...interface{})
- func DS(name string) *gorm.DB
- func DecodeURIComponent(str string) string
- func DecodedToken(tokenString string, secret string) (jwt.MapClaims, error)
- func DelCache(keys ...string)
- func DelRoutineCache(key string)
- func ERROR(v ...interface{})
- func ERRORWithFields(fields logrus.Fields, v ...interface{})
- func EncodeURIComponent(str string) string
- func EncodedToken(claims jwt.MapClaims, secret string) (signed string, err error)
- func EndOfDay(t ...time.Time) time.Time
- func EnsureDir(dir string)
- func EnumMap() map[string]*EnumDesc
- func FATAL(v ...interface{})
- func FATALWithFields(fields logrus.Fields, v ...interface{})
- func FindReadableMessageIDs(messageDB *gorm.DB, uid uint, orgIDs []uint, rolesCode []string, ...) ([]uint, error)
- func FindUnreadMessageIDs(messageDB *gorm.DB, uid uint, orgIDs []uint, rolesCode []string, ...) ([]uint, error)
- func FindUnreadMessagesCount(messageDB *gorm.DB, uid uint, orgIDs []uint, rolesCode []string) (int, error)
- func FindUnreadMessagesPrepareDB(messageDB *gorm.DB, uid uint, orgIDs []uint, rolesCode []string) (*gorm.DB, error)
- func FlatValidatorErrors(validatorErrors govalidator.Errors) []govalidator.Error
- func GenPassword(passwordSize ...int) string
- func GenRSAKey() (prvKey, pubKey []byte)
- func GenerateCaptcha() (id string, base64Str string)
- func GenerateFromPassword(p string) (string, error)
- func GetAppName() string
- func GetCacheInt(key string) (val int)
- func GetCacheString(key string) (val string)
- func GetDataScopeWheres(scope *gorm.Scope, desc *PrivilegesDesc, orgIDs []uint, ...) (sqls []string, attrs []interface{})
- func GetEnumLabel(classCode string, value interface{}) (label string)
- func GetGLSValue(key interface{}) (value interface{}, ok bool)
- func GetIntlMessages() map[string]map[string]string
- func GetIntlMessagesByLang(lang string) map[string]string
- func GetMessageCommonDB(messageDB *gorm.DB, uid uint, orgIDs []uint, rolesCode []string, ...) *gorm.DB
- func GetModPrefix(modCode string) string
- func GetPagination(ginContextOrKuuContext interface{}, ignoreDefault ...bool) (page int, size int)
- func GetPresetIntlMessage() map[string]map[string]string
- func GetRedisClient() redis.UniversalClient
- func GetRoutineCache(key string) interface{}
- func GetRoutineRequestID() string
- func GetUploadDir() string
- func HasPrefixCache(key string, limit int) (val map[string]string)
- func HasSuffixCache(key string, limit int) (val map[string]string)
- func INFO(v ...interface{})
- func INFOWithFields(fields logrus.Fields, v ...interface{})
- func If(condition bool, trueVal, falseVal interface{}) interface{}
- func IgnoreAuth(cancel ...bool) (success bool)
- func IncrCache(key string) (val int)
- func IsBlank(value interface{}) bool
- func IsNil(i interface{}) bool
- func JSON() jsoniter.API
- func JSONParse(v string, r interface{}) error
- func JSONStringify(v interface{}, format ...bool) string
- func LoadParmsFroSubApp()
- func Logout(c *Context, tx *gorm.DB) error
- func MD5(p string, upper ...bool) (v string)
- func NewCaptcha() *base64Captcha.Captcha
- func NewDateSn(keyPrefix string, valPrefix string, minLen ...int) string
- func NewIntlError(err error, id string, args ...interface{}) error
- func NewValidError(resource interface{}, column, err string) error
- func NotifyModelChange(modelName string)
- func OmitFields(src interface{}, fieldNames []string) (omitted map[string]interface{})
- func OrgIDMap(list []Org) map[uint]Org
- func PANIC(v ...interface{})
- func PANICWithFields(fields logrus.Fields, v ...interface{})
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func PRINT(v ...interface{})
- func PRINTWithFields(fields logrus.Fields, v ...interface{})
- func PSubscribeCache(patterns []string, handler func(string, string)) error
- func ParseCaptchaID(c interface{}) string
- func ParseCaptchaValue(c interface{}) string
- func ParseExcelDate(text string) (*time.Time, error)
- func ParseExcelFromFileHeader(fh *multipart.FileHeader, index int, sheetName ...string) (rows [][]string, err error)
- func ParseID(id string) uint
- func ParseJSONPath(path string) []string
- func ProjectFields(data interface{}, project string) interface{}
- func PublishCache(channel string, message interface{}) error
- func QueryCI(c *gin.Context, key string) (v string)
- func RSADecrypt(ciphertext, pubKeyBytes, privKeyBytes []byte) ([]byte, error)
- func RSAEncrypt(data, keyBytes []byte) ([]byte, error)
- func RSASignWithSha256(data []byte, keyBytes []byte) ([]byte, error)
- func RSAVerySignWithSha256(data, signData, keyBytes []byte) error
- func RandCode(size ...int) string
- func ReadData(file *excelize.File, sheet string, headers Headers) ([]map[string]string, error)
- func RegisterBizHook(name string, handler func(scope *Scope) error)
- func RegisterGormHook(name string, handler func(scope *gorm.Scope) error)
- func RegisterImportCallback(callback *ImportCallback)
- func RegisterMeta()
- func RegisterRepeatEvent(name string, interval string, data map[string]interface{}) error
- func RegisterRepeatEventProcesser(name string, processer RepeatEventProcesser)
- func Release()
- func ReloadIntlMessages() map[string]map[string]string
- func RootOrgID() uint
- func RootRoleID() uint
- func RootUID() uint
- func RunAllRunAfterJobs()
- func RunJob(codesOrNames string, sync ...bool) error
- func SetCacheInt(key string, val int, expiration ...time.Duration)
- func SetCacheString(key, val string, expiration ...time.Duration)
- func SetData(file *excelize.File, sheet string, headers Headers, ...)
- func SetGLSValues(values gls.Values, call func())
- func SetHeader(file *excelize.File, sheet string, headers Headers)
- func SetRoutineCache(key string, value interface{})
- func SetUrlQuery(rawUrl string, values map[string]interface{}, replace ...bool) string
- func Sha1(p string, upper ...bool) (v string)
- func StartOfDay(t ...time.Time) time.Time
- func SubscribeCache(channels []string, handler func(string, string)) error
- func TimeFromExcelTime(excelTime float64, date1904 bool) time.Time
- func TimeToExcelTime(t time.Time) float64
- func VerifyCaptcha(idKey, value string) bool
- func VerifyCaptchaWithClear(idKey, value string, clear bool) bool
- func WARN(v ...interface{})
- func WARNWithFields(fields logrus.Fields, v ...interface{})
- func WithTransaction(fn func(*gorm.DB) error) (err error)
- type ASCIISigner
- type AuthProcessor
- type AuthProcessorDesc
- type BatchInsertItem
- type BizPreloadInterface
- type BizQueryResult
- type BizUpdateParams
- type Cache
- type CacheBolt
- func (c *CacheBolt) Close()
- func (c *CacheBolt) Contains(pattern string, limit int) (values map[string]string)
- func (c *CacheBolt) Del(keys ...string)
- func (c *CacheBolt) GetInt(key string) (val int)
- func (c *CacheBolt) GetString(key string) (val string)
- func (c *CacheBolt) HGet(key, field string) string
- func (c *CacheBolt) HGetAll(key string) (val map[string]string)
- func (c *CacheBolt) HSet(key string, values ...string)
- func (c *CacheBolt) HasPrefix(prefix string, limit int) (values map[string]string)
- func (c *CacheBolt) HasSuffix(suffix string, limit int) (values map[string]string)
- func (c *CacheBolt) Incr(key string) (val int)
- func (c *CacheBolt) PSubscribe(patterns []string, handler func(string, string)) error
- func (c *CacheBolt) Publish(channel string, message interface{}) error
- func (c *CacheBolt) SetInt(key string, val int, expiration ...time.Duration)
- func (c *CacheBolt) SetString(key, val string, expiration ...time.Duration)
- func (c *CacheBolt) Subscribe(channels []string, handler func(string, string)) error
- type CacheRedis
- func (c *CacheRedis) Close()
- func (c *CacheRedis) Contains(rawKey string, limit int) map[string]string
- func (c *CacheRedis) Del(keys ...string)
- func (c *CacheRedis) GetInt(key string) (val int)
- func (c *CacheRedis) GetString(rawKey string) (val string)
- func (c *CacheRedis) HGet(key, field string) string
- func (c *CacheRedis) HGetAll(key string) map[string]string
- func (c *CacheRedis) HSet(key string, values ...string)
- func (c *CacheRedis) HasPrefix(rawKey string, limit int) map[string]string
- func (c *CacheRedis) HasSuffix(rawKey string, limit int) map[string]string
- func (c *CacheRedis) Incr(rawKey string) (val int)
- func (c *CacheRedis) PSubscribe(patterns []string, handler func(string, string)) error
- func (c *CacheRedis) Publish(channel string, message interface{}) error
- func (c *CacheRedis) SetInt(rawKey string, val int, expiration ...time.Duration)
- func (c *CacheRedis) SetString(rawKey, val string, expiration ...time.Duration)
- func (c *CacheRedis) Subscribe(channels []string, handler func(string, string)) error
- type Callback
- type CallbackProcessor
- func (cp *CallbackProcessor) After(callbackName string) *CallbackProcessor
- func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor
- func (cp *CallbackProcessor) Get(callbackName string) (callback func(scope *Scope))
- func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope))
- func (cp *CallbackProcessor) Remove(callbackName string)
- func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *Scope))
- type Client
- type CondDesc
- type Config
- func (c *Config) DefaultGetBool(path string, defaultValue bool) bool
- func (c *Config) DefaultGetFloat64(path string, defaultValue float64) float64
- func (c *Config) DefaultGetInt(path string, defaultValue int) int
- func (c *Config) DefaultGetString(path string, defaultValue string) string
- func (c *Config) Get(path string) (val []byte, exists bool)
- func (c *Config) GetBool(path string) (b bool)
- func (c *Config) GetFloat32(path string) float32
- func (c *Config) GetFloat64(path string) (f64 float64)
- func (c *Config) GetInt(path string) (i int)
- func (c *Config) GetInt32(path string) int32
- func (c *Config) GetInt64(path string) int64
- func (c *Config) GetInterface(path string, out interface{})
- func (c *Config) GetString(path string) (s string)
- func (c *Config) Has(path string) bool
- func (c *Config) LoadFromParams(keys ...string)
- type Context
- func (c *Context) Abort(data interface{}, args ...interface{}) *STDReply
- func (c *Context) AbortErr(err error, args ...interface{}) *STDReply
- func (c *Context) AbortErrWithCode(errData error, code int, args ...interface{}) *STDReply
- func (c *Context) DB() *gorm.DB
- func (c *Context) DEBUG(v ...interface{}) *Context
- func (c *Context) DecodedContext() (sign *SignContext, err error)
- func (c *Context) DelRoutineCache(key string)
- func (c *Context) ERROR(v ...interface{}) *Context
- func (c *Context) FATAL(v ...interface{}) *Context
- func (c *Context) FormatMessage(id, defaultMessage string, contextValues ...interface{}) string
- func (c *Context) GetIntlMessages() map[string]string
- func (c *Context) GetKey(names ...string) (value string)
- func (c *Context) GetPagination(ignoreDefault ...bool) (int, int)
- func (c *Context) GetRoutineCache(key string) interface{}
- func (c *Context) INFO(v ...interface{}) *Context
- func (c *Context) IgnoreAuth(cancel ...bool) *Context
- func (c *Context) InWhitelist() bool
- func (c *Context) L(id, defaultMessage string, contextValues ...interface{}) string
- func (c *Context) Lang() (lang string)
- func (c *Context) Origin() string
- func (c *Context) PANIC(v ...interface{}) *Context
- func (c *Context) PRINT(v ...interface{}) *Context
- func (c *Context) ParseCond(model interface{}, db *gorm.DB) (map[string]interface{}, *gorm.DB, error)
- func (c *Context) QueryCI(key string) (v string)
- func (c *Context) RequestCode(withSign ...bool) string
- func (c *Context) RequestID() string
- func (c *Context) STD(data interface{}, args ...interface{}) *STDReply
- func (c *Context) STDErr(err interface{}, args ...interface{}) *STDReply
- func (c *Context) STDErrWithCode(errData interface{}, code int, args ...interface{}) *STDReply
- func (c *Context) STDOK() *STDReply
- func (c *Context) Scheme() string
- func (c *Context) SetRoutineCache(key string, value interface{})
- func (c *Context) Token() string
- func (c *Context) WARN(v ...interface{}) *Context
- func (c *Context) WithTransaction(fn func(*gorm.DB) error) error
- type CreateOrgArgs
- type CreateOrgReply
- type D
- type DBTypeRepairer
- type DataPrivileges
- type DefaultAuthProcessor
- type Doc
- type DocComponent
- type DocComponentSchema
- type DocInfo
- type DocInfoContact
- type DocPathContentItem
- type DocPathItem
- type DocPathItemSecurity
- type DocPathItems
- type DocPathParameter
- type DocPathRequestBody
- type DocPathResponse
- type DocPathSchema
- type DocSchemaProperty
- type DocSecurityScheme
- type DocServer
- type DocTag
- type Engine
- func (app *Engine) Any(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) DELETE(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) Group(relativePath string, handlers ...HandlerFunc) *gin.RouterGroup
- func (app *Engine) HEAD(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) Import(mods ...*Mod)
- func (app *Engine) OPTIONS(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) PATCH(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) PUT(relativePath string, handlers ...HandlerFunc) gin.IRoutes
- func (app *Engine) RegisterWhitelist(rules ...interface{})
- func (app *Engine) Run(addr ...string)
- func (app *Engine) RunTLS(addr, certFile, keyFile string)
- func (app *Engine) Use(handlers ...HandlerFunc) *Engine
- func (app *Engine) UseGin(handlers ...gin.HandlerFunc) *Engine
- type EnumDesc
- type EnumItem
- type EventLog
- type EventLogLabel
- type ExtendField
- type File
- type GenTokenDesc
- type HandlerFunc
- type HandlersChain
- type Header
- type Headers
- type HookHandler
- type Hub
- type IPInfo
- type ImportCallback
- type ImportCallbackProcessor
- type ImportCallbackResult
- type ImportCallbackValidator
- type ImportContext
- type ImportFeedback
- type ImportRecord
- type IntlError
- type IntlMessagesOptions
- type Job
- type JobContext
- type LogDailyFileHook
- type LoginHandlerFunc
- type LoginHandlerResponse
- type Menu
- type MenuList
- type Message
- type MessageReceipt
- type Messages
- type Metadata
- type MetadataField
- type Mod
- type Model
- type ModelExDel
- type ModelExOrg
- type OperationPrivileges
- type Org
- type Param
- type PrivilegesDesc
- func (desc *PrivilegesDesc) HasPermission(permission string) bool
- func (desc *PrivilegesDesc) HasRole(code string) bool
- func (desc *PrivilegesDesc) IsLoginableOrgID(orgID uint) bool
- func (desc *PrivilegesDesc) IsReadableOrgID(orgID uint) bool
- func (desc *PrivilegesDesc) IsValid() bool
- func (desc *PrivilegesDesc) IsWritableOrgID(orgID uint) bool
- func (desc *PrivilegesDesc) NotRootUser() bool
- type REContext
- type RepeatEvent
- type RepeatEventProcesser
- type RestDesc
- type Role
- type RoleAssign
- type RouteInfo
- type RoutesInfo
- type RoutineCaches
- type STDReply
- type Scope
- type SignContext
- type SignHistory
- type SignSecret
- type User
- func (u *User) AfterDelete()
- func (u *User) BeforeSave(scope *gorm.Scope) (err error)
- func (u *User) DelSubDocID(signType string) error
- func (u *User) GetSubDocID(signType string) (uint, error)
- func (u *User) GetSubDocIDs() (v map[string]uint, err error)
- func (u *User) SetSubDocID(signType string, subDocID uint) error
- func (u *User) SetSubDocIDs(v map[string]uint)
- type ValidError
Examples ¶
Constants ¶
const ( SignMethodLogin = "LOGIN" SignMethodLogout = "LOGOUT" )
const ( // BizCreateKind BizCreateKind = "create" // BizUpdateKind BizUpdateKind = "update" // BizDeleteKind BizDeleteKind = "delete" // BizQueryKind BizQueryKind = "query" )
const ( ImportStatusImporting = "importing" ImportStatusSuccess = "success" ImportStatusFailed = "failed" )
const ( MessageStatusDraft = 100 MessageStatusSent = 200 )
const ( ASCIISignerAlgMD5 = "MD5" ASCIISignerAlgSHA1 = "SHA1" )
const ( // DataScopePersonal DataScopePersonal = "PERSONAL" // DataScopeCurrent DataScopeCurrent = "CURRENT" // DataScopeCurrentFollowing DataScopeCurrentFollowing = "CURRENT_FOLLOWING" )
const (
AdminSignType = "ADMIN"
)
Variables ¶
var ( TokenKey = "Token" LangKey = "Lang" Whitelist = []interface{}{ "GET /", "GET /favicon.ico", "POST /login", "GET /model/docs", "GET /model/ws", "GET /language", "GET /langmsgs", "GET /captcha", "GET /intl/languages", "GET /intl/messages", regexp.MustCompile("GET /assets"), } ExpiresSeconds = 86400 )
var ( // CaptchaIDKey CaptchaIDKey = "captcha_id" // CaptchaValKey CaptchaValKey = "captcha_val" )
var ( ErrTokenNotFound = errors.New("token not found") ErrSecretNotFound = errors.New("secret not found") ErrInvalidToken = errors.New("invalid token") ErrAffectedSaveToken = errors.New("未新增或修改任何记录,请检查更新条件或数据权限") ErrAffectedDeleteToken = errors.New("未删除任何记录,请检查更新条件或数据权限") )
var ( // GLSPrisDescKey GLSPrisDescKey = "PrisDesc" // GLSSignInfoKey GLSSignInfoKey = "SignInfo" // GLSIgnoreAuthKey GLSIgnoreAuthKey = "IgnoreAuth" // GLSRoutineCachesKey GLSRoutineCachesKey = "RoutineCaches" // GLSRequestContextKey GLSRequestContextKey = "RequestContext" GLSRequestIDKey = "Request ID" // Uptime Uptime time.Time // IsProduction IsProduction = os.Getenv("GIN_MODE") == "release" || os.Getenv("KUU_PROD") == "true" )
var ( Logger = logrus.New() DailyFileName = fmt.Sprintf("kuu-%s.log", time.Now().Format("2006-01-02")) DailyFile *os.File LogDir string )
var ( // CreateCallback CreateCallback = createCallback // BeforeQueryCallback BeforeQueryCallback = beforeQueryCallback // DeleteCallback DeleteCallback = deleteCallback // UpdateCallback UpdateCallback = updateCallback // AfterSaveCallback AfterSaveCallback = afterSaveCallback // QueryCallback QueryCallback = queryCallback // ValidateCallback ValidateCallback = validateCallback )
var APIKeyRoute = RouteInfo{ Name: "令牌生成接口", Method: "POST", Path: "/apikeys", IntlMessages: map[string]string{ "apikeys_failed": "Create API Keys failed.", }, HandlerFunc: func(c *Context) *STDReply { var body GenTokenDesc if err := c.ShouldBindJSON(&body); err != nil { return c.STDErr(err, "apikeys_failed") } body.Payload = c.SignInfo.Payload body.UID = c.SignInfo.UID body.IsAPIKey = true body.Type = AdminSignType secretData, err := GenToken(body) if err != nil { return c.STDErr(err, "apikeys_failed") } return c.STD(secretData.Token) }, }
APIKeyRoute
var ActiveAuthProcessor = DefaultAuthProcessor{}
ActiveAuthProcessor
var AuthRoute = RouteInfo{ Name: "操作权限鉴权接口", Method: "GET", Path: "/auth", IntlMessages: map[string]string{ "auth_failed": "Authentication failed", }, HandlerFunc: func(c *Context) *STDReply { ps := c.Query("p") split := strings.Split(ps, ",") if len(split) == 0 { return c.STDErr(errors.New("param 'p' is required"), "auth_failed") } ret := make(map[string]bool) for _, s := range split { _, has := c.PrisDesc.PermissionMap[s] ret[s] = has } return c.STD(ret) }, }
AuthRoute
var CaptchaRoute = RouteInfo{ Name: "查询验证码", Path: "/captcha", Method: "GET", HandlerFunc: func(c *Context) *STDReply { var ( user = c.Query("user") valid bool ) if user != "" { times := GetCacheInt(getFailedTimesKey(user)) valid = failedTimesValid(times) } if valid == false { return c.STD(null.BoolFrom(valid)) } id, base64Str := GenerateCaptcha() c.SetCookie(CaptchaIDKey, id, ExpiresSeconds, "/", "", false, true) return c.STD(D{ "id": id, "base64Str": base64Str, }) }, }
CaptchaRoute
var ChangePassword = RouteInfo{ Name: "修改密码", Method: "POST", Path: "/changepasswd", IntlMessages: map[string]string{ "parse_body_failed": "解析请求参数失败", "oldpasswd_error": "旧密码错误", "newpasswd_error": "新密码错误", }, HandlerFunc: func(c *Context) *STDReply { var body = struct { OldPasswd string `binding:"required"` NewPasswd string `binding:"required"` }{} if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil { return c.STDErr(err, "parse_body_failed") } var user User DB().Model(&User{}).Where("id = ?", c.PrisDesc.UID).First(&user) if user.ID == 0 { return c.STDErr(errors.New("用户不存在"), "parse_body_failed") } body.OldPasswd = strings.ToLower(body.OldPasswd) if err := CompareHashAndPassword(user.Password, body.OldPasswd); err != nil { return c.STDErr(err, "oldpasswd_error") } passwd, err := GenerateFromPassword(strings.ToLower(body.NewPasswd)) if err != nil { return c.STDErr(err, "newpasswd_error") } DB().Model(&User{}). Where("id = ?", c.PrisDesc.UID). Updates(map[string]any{ "Password": passwd, "LastChangePasswordTime": time.Now(), }) return c.STDOK() }, }
var DataDictRoute = RouteInfo{ Name: "查询数据字典", Method: "GET", Path: "/datadict", HandlerFunc: func(c *Context) *STDReply { modCode := c.Query("modCode") var buff strings.Builder buff.WriteString(fmt.Sprintf("# %s数据字典\n\n", C().GetString("name"))) var modname string bookmap := map[bool]string{true: "是", false: "否"} m := DefaultCache.HGetAll(BuildKey("datadict")) var keys []string for k, _ := range m { keys = append(keys, k) } sort.Strings(keys) for _, key := range keys { item := m[key] var meta Metadata err := JSONParse(item, &meta) if err != nil { return c.STDErr(err) } if meta.ModCode == "" { continue } if modCode != "" && meta.ModCode != modCode { continue } if modname != meta.ModCode { modname = meta.ModCode buff.WriteString(fmt.Sprintf("## %s\n\n", meta.ModCode)) } buff.WriteString(fmt.Sprintf("### %s_%s %s\n\n", meta.ModCode, meta.NativeName, meta.DisplayName)) buff.WriteString("|字段名|字段类型|是否可空|是否主键|注释|\n") buff.WriteString("| :--- | :--- | :--- | :--- | :--- |\n") for _, field := range meta.Fields { IsBland := bookmap[field.IsBland] IsPrimaryKey := bookmap[field.IsPrimaryKey] line := fmt.Sprintf("| %s | %s | %s | %s | %s |\n", field.NativeName, field.DBType, IsBland, IsPrimaryKey, field.Name) buff.WriteString(line) } buff.WriteString("\n\n") } c.String(http.StatusOK, buff.String()) return nil }, }
DataDictRoute
var DefaultCallback = &Callback{}
DefaultCallback
var DefaultCron = cron.New(cron.WithSeconds())
DefaultCron (set option 5 cron to convet 6 cron)
var EnumKey = BuildKey("EMUM")
var EnumRoute = RouteInfo{ Name: "查询枚举列表", Path: "/enum", Method: "GET", HandlerFunc: func(c *Context) *STDReply { json := c.Query("json") name := c.Query("name") em := EnumMap() var list []*EnumDesc if name != "" { for _, name := range strings.Split(name, ",") { if v, ok := em[name]; ok && v != nil { list = append(list, v) } } } else { list = EnumList() } if json != "" { return c.STD(list) } else { var buffer bytes.Buffer for _, desc := range list { if desc.ClassName != "" { buffer.WriteString(fmt.Sprintf("%s(%s) {\n", desc.ClassCode, desc.ClassName)) } else { buffer.WriteString(fmt.Sprintf("%s {\n", desc.ClassCode)) } index := 0 for value, label := range desc.Values { if len(label) < 20 { for i := 0; i < 20-len(label); i++ { label += " " } } buffer.WriteString(fmt.Sprintf("\t%s\t%v(%s)", label, value, reflect.ValueOf(value).Type().Kind().String())) if index != len(desc.Values)-1 { buffer.WriteString("\n") } index++ } buffer.WriteString(fmt.Sprintf("\n}\n\n")) } c.String(http.StatusOK, buffer.String()) return nil } }, }
EnumRoute
var GetUserWithRoles = func(uid uint) (*User, error) { // 查询用户档案 var user User if err := DB().Where("id = ?", uid).Preload("RoleAssigns").First(&user).Error; err != nil { return &user, err } // 过滤有效的角色分配 var roleIDs []uint for _, assign := range user.RoleAssigns { if assign.ExpireUnix <= 0 || time.Now().Before(time.Unix(assign.ExpireUnix, 0)) { roleIDs = append(roleIDs, assign.RoleID) } } // 查询角色档案 var ( roles []Role roleMap = make(map[uint]Role) ) if err := DB().Where("id in (?)", roleIDs).Preload("OperationPrivileges").Preload("DataPrivileges").Find(&roles).Error; err != nil { return &user, err } for _, role := range roles { roleMap[role.ID] = role } for index, assign := range user.RoleAssigns { role := roleMap[assign.RoleID] assign.Role = &role user.RoleAssigns[index] = assign } return &user, nil }
GetUserWithRoles
var ImportRoute = RouteInfo{ Name: "统一导入路由", Method: "POST", Path: "/import", IntlMessages: map[string]string{ "import_failed": "Import failed", "import_empty": "Import data is empty", }, HandlerFunc: func(c *Context) *STDReply { file, _ := c.FormFile("file") if file == nil { return c.STDErr(errors.New("no 'file' key in form-data"), "import_failed") } channel := c.PostForm("channel") if channel == "" { return c.STDErr(errors.New("no 'channel' key in form-data"), "import_failed") } if importCallbackMap[channel] == nil { return c.STDErr(fmt.Errorf("no import callback registered for this channel: %s", channel), "import_failed") } var ( sheetIndex int sheetName string ) sheetName = c.PostForm("sheet_name") if v := c.PostForm("sheet_idx"); v != "" { idx, err := strconv.Atoi(v) if err == nil { sheetIndex = idx } } rows, err := ParseExcelFromFileHeader(file, sheetIndex, sheetName) if err != nil { return c.STDErr(err, "import_failed") } if len(rows) == 0 { return c.STDErr(err, "import_empty") } args := importCallbackMap[channel] if args.Validator != nil { if std, err := args.Validator(c, rows); err != nil { return std } } record := ImportRecord{ Channel: channel, Data: JSONStringify(rows), Sync: c.PostForm("sync") != "", Context: JSONStringify(&ImportContext{ Token: c.SignInfo.Token, SignType: c.SignInfo.Type, Lang: c.SignInfo.Lang, UID: c.SignInfo.UID, SubDocID: c.SignInfo.SubDocID, ActOrgID: c.PrisDesc.ActOrgID, ActOrgCode: c.PrisDesc.ActOrgCode, ActOrgName: c.PrisDesc.ActOrgName, }), } if err := c.DB().Create(&record).Error; err != nil { return c.STDErr(err, "import_failed") } if record.Sync { if _, err := CallImportCallback(c, &record); err != nil { if _, ok := err.(*IntlError); ok { return c.STDErr(err) } return c.STDErr(err, "import_failed") } } else { go func() { _, _ = CallImportCallback(c, &record) }() } return c.STD(record.ImportSn) }, }
ImportRoute
var ImportTemplateRoute = RouteInfo{ Name: "导入模板下载", Method: "GET", Path: "/import/template", IntlMessages: map[string]string{ "import_template_failed": "Import template download failed", }, HandlerFunc: func(c *Context) *STDReply { channel := c.Query("channel") format := strings.ToLower(c.DefaultQuery("format", "file")) if channel == "" { return c.STDErr(errors.New("no 'channel' key in query parameters"), "import_template_failed") } callback := importCallbackMap[channel] if callback == nil { return c.STDErr(fmt.Errorf("no import callback registered for this channel: %s", channel), "import_template_failed") } if callback.TemplateGenerator == nil { return c.STDErr(fmt.Errorf("no template generator registered for this channel: %s", channel), "import_template_failed") } fileName, headers := callback.TemplateGenerator(c) switch format { case "json": c.STD(headers) case "file": if !strings.HasSuffix(fileName, ".xlsx") { fileName = fmt.Sprintf("%s.xlsx", fileName) } fileName = url.QueryEscape(fileName) f := excelize.NewFile() if err := f.SetSheetRow("Sheet1", "A1", &headers); err != nil { return c.STDErr(err, "import_template_failed") } c.Header("Content-Transfer-Encoding", "binary") c.Header("Content-Disposition", "attachment; filename="+fileName) c.Header("Content-Type", "application/octet-stream") f.SetActiveSheet(1) if err := f.Write(c.Writer); err != nil { return c.STDErr(err, "import_template_failed") } } return c.STDOK() }, }
ImportTemplateRoute
var InjectCreateAuth = func(signType string, auth AuthProcessorDesc) (replace bool, err error) {
return
}
InjectCreateAuth
var InjectReadableAuth = func(signType string, auth AuthProcessorDesc) (replace bool, err error) {
return
}
InjectReadableAuth
var InjectWritableAuth = func(signType string, auth AuthProcessorDesc) (replace bool, err error) {
return
}
InjectWritableAuth
var IntlLanguagesRoute = RouteInfo{ Name: "查询语言列表", Method: http.MethodGet, Path: "/intl/languages", HandlerFunc: func(c *Context) *STDReply { list := intl.LanguageList() return c.STD(list) }, }
var IntlMessagesRoute = RouteInfo{ Name: "查询消息列表", Method: http.MethodGet, Path: "/intl/messages", IntlMessages: map[string]string{ "intl_messages_failed": "You must and only specify one language code, like 'langs=zh-Hans'", }, HandlerFunc: func(c *Context) *STDReply { var query struct { LanguageCodes string `form:"langs"` Prefix string `form:"prefix"` Suffix string `form:"suffix"` Contains string `form:"contains"` Description string `form:"desc"` Keys string `form:"keys"` Simple string `form:"simple"` } _ = c.ShouldBindQuery(&query) var simple bool if v, err := strconv.ParseBool(query.Simple); err == nil { simple = v } if simple { if query.LanguageCodes == "" { query.LanguageCodes = c.Lang() } if strings.Contains(query.LanguageCodes, ",") { query.LanguageCodes = strings.Split(query.LanguageCodes, ",")[0] } query.LanguageCodes = intl.ConvertLanguageCode(query.LanguageCodes) } opts := IntlMessagesOptions{ LanguageCodes: query.LanguageCodes, Prefix: query.Prefix, Suffix: query.Suffix, Contains: query.Contains, Description: query.Description, Keys: query.Keys, } var ret interface{} if simple { ret = getIntlMessagesByLang(&opts) } else { ret = getIntlMessages(&opts) } return c.STD(ret) }, }
var IntlMessagesSaveRoute = RouteInfo{ Name: "修改/新增翻译键", Method: http.MethodPost, Path: "/intl/messages/save", IntlMessages: map[string]string{ "intl_messages_save_failed": "Save failed.", }, HandlerFunc: func(c *Context) *STDReply { var messages map[string]map[string]string if err := c.ShouldBindJSON(&messages); err != nil { return c.STDErr(err, "intl_messages_save_failed") } if err := saveIntlMessages(messages, false); err != nil { return c.STDErr(err, "intl_messages_save_failed") } return c.STDOK() }, }
var IntlMessagesUploadRoute = RouteInfo{ Name: "批量上传翻译文件", Method: http.MethodPost, Path: "/intl/messages/upload", IntlMessages: map[string]string{ "intl_messages_upload_failed": "Upload failed.", }, HandlerFunc: func(c *Context) *STDReply { updateMethod := c.DefaultPostForm("method", "incr") fh, err := c.FormFile("file") if err != nil { return c.STDErr(err, "intl_messages_upload_failed") } var ( sheetIndex int sheetName string ) sheetName = c.PostForm("sheet_name") if v := c.PostForm("sheet_idx"); v != "" { idx, err := strconv.Atoi(v) if err == nil { sheetIndex = idx } } rows, err := ParseExcelFromFileHeader(fh, sheetIndex, sheetName) if err != nil { return c.STDErr(err, "intl_messages_upload_failed") } if len(rows) == 0 { return c.STDOK() } languages := intl.LanguageList() indexLangCodeMap := map[int]string{ 0: "key", 1: "default", 2: "en", 3: "zh-Hans", 4: "zh-Hant", } i := len(indexLangCodeMap) for _, item := range languages { if item.Code == "en" || item.Code == "zh-Hans" || item.Code == "zh-Hant" { continue } indexLangCodeMap[i] = item.Code i++ } messages := make(map[string]map[string]string) for i := 1; i < len(rows); i++ { row := rows[i] key := strings.TrimSpace(row[0]) if key == "" { continue } for j := 1; j < len(row); j++ { value := strings.TrimSpace(row[j]) if value == "" { continue } lang := indexLangCodeMap[j] if messages[key] == nil { messages[key] = make(map[string]string) } messages[key][lang] = value } } if err := saveIntlMessages(messages, updateMethod == "overwrite"); err != nil { return c.STDErr(err, "intl_messages_upload_failed") } return c.STDOK() }, }
var JobRunRoute = RouteInfo{ Name: "触发定时任务立即运行接口", Method: http.MethodPost, Path: "/job/run", HandlerFunc: func(c *Context) *STDReply { if err := RunJob(c.Query("code")); err != nil { return c.STDErr(err) } return c.STDOK() }, }
JobRunRoute
var LangSwitchRoute = RouteInfo{ Name: "切换用户语言环境", Method: "POST", Path: "/lang/switch", IntlMessages: map[string]string{ "lang_switch_failed": "Switching language failed", }, HandlerFunc: func(c *Context) *STDReply { var body struct { Lang string } if err := c.ShouldBindJSON(&body); err != nil { return c.STDErr(err, "lang_switch_failed") } err := c.IgnoreAuth().DB(). Model(&User{ID: c.SignInfo.UID}). Update(User{Lang: body.Lang}).Error if err != nil { return c.STDErr(err, "lang_switch_failed") } return c.STDOK() }, }
LangSwitchRoute
var LoginAsOutRoute = RouteInfo{ Name: "退出模拟登录(该接口仅限root调用)", Method: "DELETE", Path: "/login_as", HandlerFunc: func(c *Context) *STDReply { c.SetCookie(TokenKey, c.SignInfo.Token, -1, "/", "", false, true) c.SetCookie(LangKey, "", -1, "/", "", false, true) return c.STDOK() }, }
LoginAsOutRoute
var LoginAsRoute = RouteInfo{ Name: "以用户身份登录(该接口仅限root调用)", Method: "POST", Path: "/login_as", IntlMessages: map[string]string{ "login_as_unauthorized": "Unauthorized operation", "login_as_failed": "Login failed", }, HandlerFunc: func(c *Context) *STDReply { var body struct { UID uint } if c.SignInfo.UID != RootUID() { return c.STDErr(fmt.Errorf("unauthorized operation: uid=%v", c.SignInfo.UID), "login_as_unauthorized") } if err := c.ShouldBindJSON(&body); err != nil { return c.STDErr(err, "login_as_failed") } var ( secret SignSecret user User db = c.DB() ) if err := db.Where(&SignSecret{UID: body.UID, Type: AdminSignType, Method: "LOGIN"}).Where(fmt.Sprintf("%s > ?", db.Dialect().Quote("exp")), time.Now().Unix()).Order("created_at desc").First(&secret).Error; err != nil { return c.STDErr(err, "login_as_failed") } if err := db.Where(fmt.Sprintf("%s = ?", db.Dialect().Quote("id")), secret.UID).First(&user).Error; err != nil { return c.STDErr(err, "login_as_failed") } c.SetCookie(LangKey, user.Lang, ExpiresSeconds, "/", "", false, true) c.SetCookie(TokenKey, secret.Token, ExpiresSeconds, "/", "", false, true) return c.STDOK() }, }
LoginAsRoute
var LoginAsUsersRoute = RouteInfo{ Name: "查询可模拟登录的用户列表(该接口仅限root调用)", Method: "GET", Path: "/login_as/users", IntlMessages: map[string]string{ "login_as_unauthorized": "Unauthorized operation", "login_as_failed": "Login failed", }, HandlerFunc: func(c *Context) *STDReply { if c.SignInfo.UID != RootUID() { return c.STDErr(fmt.Errorf("unauthorized operation: uid=%v", c.SignInfo.UID), "login_as_unauthorized") } var ( secrets []SignSecret uids []uint users []User db = c.DB() ) if err := db.Model(&SignSecret{}).Where(&SignSecret{Type: AdminSignType, Method: "LOGIN"}).Where(fmt.Sprintf("%s > ?", db.Dialect().Quote("exp")), time.Now().Unix()).Find(&secrets).Error; err != nil { return c.STDErr(err, "login_as_failed") } secretMap := make(map[uint]SignSecret) for _, item := range secrets { uids = append(uids, item.UID) secretMap[item.UID] = item } if err := db.Model(&User{}).Where(fmt.Sprintf("%s IN (?)", db.Dialect().Quote("id")), uids).Find(&users).Error; err != nil { return c.STDErr(err, "login_as_failed") } type record struct { ID uint Name string Username string Exp int64 } var records []record for _, item := range users { records = append(records, record{ ID: item.ID, Name: item.Name, Username: item.Username, Exp: secretMap[item.ID].Exp, }) } return c.STD(records) }, }
LoginAsUsersRoute
var LoginRoute = RouteInfo{ Name: "默认登录接口", Method: "POST", Path: "/login", IntlMessages: map[string]string{ "acc_login_failed": "Login failed", }, HandlerFunc: func(c *Context) *STDReply { if loginHandler == nil { PANIC("login handler not configured") } resp := loginHandler(c) if resp.Error != nil { if resp.LocaleMessageID != "" { return c.STDErr(resp.Error, resp.LocaleMessageID, resp.LocaleMessageDefaultText, resp.LocaleMessageContextValues) } return c.STDErr(resp.Error, "acc_login_failed") } secretData, err := GenToken(GenTokenDesc{ UID: resp.UID, Username: resp.Username, Payload: resp.Payload, Exp: time.Now().Add(time.Second * time.Duration(ExpiresSeconds)).Unix(), Type: AdminSignType, }) if err != nil { return c.STDErr(err, "acc_login_failed") } c.Set("__kuu_sign_context__", &SignContext{ Token: secretData.Token, UID: secretData.UID, Payload: resp.Payload, Secret: secretData, }) c.SetCookie(LangKey, resp.Lang, ExpiresSeconds, "/", "", false, true) c.SetCookie(TokenKey, secretData.Token, ExpiresSeconds, "/", "", false, true) c.SetCookie(CaptchaIDKey, "", -1, "/", "", false, true) DelCache(getFailedTimesKey(resp.Username)) return c.STD(resp.Payload) }, }
LoginRoute
var LogoutRoute = RouteInfo{ Name: "默认登出接口", Method: "POST", Path: "/logout", IntlMessages: map[string]string{ "acc_logout_failed": "Logout failed", }, HandlerFunc: func(c *Context) *STDReply { if err := Logout(c, c.DB()); err != nil { return c.STDErr(err, "acc_logout_failed") } return c.STDOK() }, }
LogoutRoute
var MessagesLatestRoute = RouteInfo{ Name: "查询当前用户最新消息", Method: http.MethodGet, Path: "/messages/latest", IntlMessages: map[string]string{ "messages_latest_failed": "Get latest messages failed.", }, HandlerFunc: func(c *Context) *STDReply { c.IgnoreAuth() defer c.IgnoreAuth(true) var query struct { Limit string `form:"limit"` RecipientIDs string `form:"recipient_ids"` } if err := c.ShouldBindQuery(&query); err != nil { return c.STDErr(err, "messages_latest_failed") } var ( limit int recipientIDs []uint ) if s := c.DefaultQuery("limit", "10"); s != "" { if v, err := strconv.Atoi(s); err == nil { limit = v } } if s := c.Query("recipient_ids"); s != "" { ss := strings.Split(s, ",") for _, item := range ss { item = strings.TrimSpace(item) if item == "" { continue } if v, err := strconv.Atoi(item); err == nil { recipientIDs = append(recipientIDs, uint(v)) } } } type replyItem struct { Messages Messages UnreadCount int } var reply struct { replyItem RecipientMap map[uint]replyItem `json:",omitempty"` } if len(recipientIDs) > 0 { reply.RecipientMap = make(map[uint]replyItem) for _, itemId := range recipientIDs { baseMessageDB := c.DB().Model(&Message{}).Where("sender_id = ? OR recipient_user_ids LIKE ?", itemId, "%"+fmt.Sprintf("%d", itemId)+"%") messsagesDB := GetMessageCommonDB(baseMessageDB, c.SignInfo.UID, c.PrisDesc.ReadableOrgIDs, c.PrisDesc.RolesCode, 1, limit) if _, v, err := c.ParseCond(&Message{}, messsagesDB); err != nil { return c.STDErr(err, "messages_latest_failed") } else { messsagesDB = v } var messages Messages if err := messsagesDB.Preload("Attachments").Find(&messages).Error; err != nil { return c.STDErr(err, "messages_latest_failed") } sort.Sort(messages) item := replyItem{Messages: messages} count, err := FindUnreadMessagesCount(baseMessageDB, c.SignInfo.UID, c.PrisDesc.ReadableOrgIDs, c.PrisDesc.RolesCode) if err != nil { return c.STDErr(err, "messages_latest_failed") } item.UnreadCount = count reply.RecipientMap[itemId] = item } } else { messsagesDB := GetMessageCommonDB(c.DB().Model(&Message{}), c.SignInfo.UID, c.PrisDesc.ReadableOrgIDs, c.PrisDesc.RolesCode, 1, limit) if _, v, err := c.ParseCond(&Message{}, messsagesDB); err != nil { return c.STDErr(err, "messages_latest_failed") } else { messsagesDB = v } var messages Messages if err := messsagesDB.Preload("Attachments").Find(&messages).Error; err != nil { return c.STDErr(err, "messages_latest_failed") } sort.Sort(messages) reply.Messages = messages } count, err := FindUnreadMessagesCount(c.DB().Model(&Message{}), c.SignInfo.UID, c.PrisDesc.ReadableOrgIDs, c.PrisDesc.RolesCode) if err != nil { return c.STDErr(err, "messages_latest_failed") } reply.UnreadCount = count return c.STD(&reply) }, }
var MessagesReadRoute = RouteInfo{ Name: "阅读消息", Method: http.MethodPost, Path: "/messages/read", IntlMessages: map[string]string{ "messages_read_failed": "Update message status failed.", }, HandlerFunc: func(c *Context) *STDReply { c.IgnoreAuth() defer c.IgnoreAuth(true) var body struct { MessageIDs []uint RecipientIDs []uint All bool } if err := c.ShouldBindJSON(&body); err != nil { return c.STDErr(err, "messages_read_failed") } if !body.All && len(body.MessageIDs) == 0 && len(body.RecipientIDs) == 0 { return c.STDOK() } err := c.WithTransaction(func(tx *gorm.DB) error { messageDB := tx.Model(&Message{}) if !body.All { if len(body.MessageIDs) > 0 { messageDB = messageDB.Where(fmt.Sprintf("%s IN (?)", messageDB.Dialect().Quote("id")), body.MessageIDs) } if len(body.RecipientIDs) > 0 { var ( sqls []string attrs []interface{} ) for _, itemId := range body.RecipientIDs { sqls = append(sqls, "(sender_id = ? OR recipient_user_ids LIKE ?)") attrs = append(attrs, itemId, "%"+fmt.Sprintf("%d", itemId)+"%") } messageDB = messageDB.Where(strings.Join(sqls, " OR "), attrs...) } } unreadMessageIDs, err := FindUnreadMessageIDs(messageDB, c.SignInfo.UID, c.PrisDesc.ReadableOrgIDs, c.PrisDesc.RolesCode, 0, 0) if err != nil { return err } for _, item := range unreadMessageIDs { if err := tx.Model(&MessageReceipt{}).Create(&MessageReceipt{ MessageID: item, RecipientID: c.SignInfo.UID, RecipientUsername: c.SignInfo.Username, RecipientSourceIP: c.ClientIP(), ReadAt: null.TimeFrom(time.Now()), }).Error; err != nil { return err } } return tx.Error }) if err != nil { return c.STDErr(err, "messages_read_failed") } return c.STDOK() }, }
var MetaRoute = RouteInfo{ Name: "查询元数据列表", Method: "GET", Path: "/meta", HandlerFunc: func(c *Context) *STDReply { json := c.Query("json") name := c.Query("name") mod := c.Query("mod") var list []*Metadata if name != "" { for _, name := range strings.Split(name, ",") { if v, ok := metadataMap[name]; ok && v != nil { list = append(list, v) } } } else if mod != "" { for _, item := range strings.Split(mod, ",") { for _, meta := range metadataList { if meta.ModCode == item { list = append(list, meta) } } } } else { list = metadataList } if json != "" { return c.STD(list) } else { var ( hashKey = fmt.Sprintf("meta_%s_%s", name, mod) result string ) if v, ok := valueCacheMap.Load(hashKey); ok { result = v.(string) } else { var buffer bytes.Buffer for _, m := range list { if len(m.Fields) > 0 { if m.DisplayName != "" { buffer.WriteString(fmt.Sprintf("%s(%s) {\n", m.Name, m.DisplayName)) } else { buffer.WriteString(fmt.Sprintf("%s {\n", m.Name)) } for index, field := range m.Fields { if field.Enum != "" { buffer.WriteString(fmt.Sprintf("\t%s %s ENUM(%s)", field.Code, field.Name, field.Enum)) } else { buffer.WriteString(fmt.Sprintf("\t%s %s %s", field.Code, field.Name, field.Type)) } if index != len(m.Fields)-1 { buffer.WriteString("\n") } } buffer.WriteString(fmt.Sprintf("\n}\n\n")) } } result = buffer.String() valueCacheMap.Store(hashKey, result) } c.String(http.StatusOK, result) return nil } }, }
MetaRoute
var ModelDocsRoute = RouteInfo{ Name: "查询默认接口文档", Method: "GET", Path: "/model/docs", IntlMessages: map[string]string{ "model_docs_failed": "Model document query failed", }, HandlerFunc: func(c *Context) *STDReply { var ( hashKeyYAML = "model_docs_yaml" hashKeyJSON = "model_docs_json" ) json := c.Query("json") != "" if json { if v, ok := valueCacheMap.Load(hashKeyJSON); ok { c.String(http.StatusOK, v.(string)) return nil } } else { if v, ok := valueCacheMap.Load(hashKeyYAML); ok { c.String(http.StatusOK, v.(string)) return nil } } // 重新生成 var validMeta []*Metadata for _, m := range metadataList { if m == nil || m.RestDesc == nil || !m.RestDesc.IsValid() || len(m.Fields) == 0 { continue } validMeta = append(validMeta, m) } name := GetAppName() doc := Doc{ Openapi: "3.0.1", Info: DocInfo{ Title: fmt.Sprintf("%s 模型默认接口文档", name), Description: "调用说明:\n" + "1. 本文档仅包含数据模型默认开放的增删改查RESTful接口\n" + "1. 接口请求/响应的Content-Type默认为application/json,UTF-8编码\n" + "1. 如未额外说明,接口响应格式默认为以下JSON格式:\n" + "\t- `code` - **业务状态码**,0表成功,非0表失败(错误码默认为-1,令牌失效为555),该值一定存在,请按照该值判断业务操作是否成功,`integer`\n" + "\t- `msg` - **提示信息**,表正常或异常情况下的提示信息,有值才存在,`string`\n" + "\t- `data` - **数据部分**,正常时返回请求数据,异常时返回错误详情,有值才存在,`类型视具体接口而定`\n" + "1. 日期格式为`2019-06-04T02:42:01.472Z`,js代码:`new Date().toISOString()`\n" + "1. 用户密码等信息统一为MD5加密后的32位小写字符串,npm推荐使用blueimp-md5" + "", Version: "1.0.0", Contact: DocInfoContact{ Email: "yinfxs@dexdev.me", }, }, Servers: []DocServer{ {Url: fmt.Sprintf("%s%s", c.Origin(), C().GetString("prefix")), Description: "默认服务器"}, }, Tags: func() (tags []DocTag) { tags = []DocTag{{Name: "辅助接口"}} for _, m := range validMeta { tags = append(tags, DocTag{ Name: m.Name, Description: m.DisplayName, }) } return }(), Paths: func() (paths map[string]DocPathItems) { paths = map[string]DocPathItems{ "/meta": { "get": { Tags: []string{"辅助接口"}, Summary: "查询模型列表", OperationID: "meta", Responses: map[int]DocPathResponse{ 200: { Description: "查询模型列表成功", Content: map[string]DocPathContentItem{ "text/plain": { Schema: DocPathSchema{Type: "string"}, }, }, }, }, }, }, "/enum": { "get": { Tags: []string{"辅助接口"}, Summary: "查询枚举列表", OperationID: "enum", Responses: map[int]DocPathResponse{ 200: { Description: "查询枚举列表成功", Content: map[string]DocPathContentItem{ "text/plain": { Schema: DocPathSchema{Type: "string"}, }, }, }, }, }, }, "/upload": { "post": { Tags: []string{"辅助接口"}, Summary: "上传文件", OperationID: "upload", RequestBody: DocPathRequestBody{ Content: map[string]DocPathContentItem{ "multipart/form-data": { Schema: DocPathSchema{ Type: "object", Properties: map[string]DocPathSchema{ "file": { Type: "string", Format: "binary", Description: "文件", }, }, }, }, }, }, Responses: map[int]DocPathResponse{ 200: { Description: "上传成功", Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{Type: "string"}, }, }, }, }, Security: []DocPathItemSecurity{ map[string][]string{ "api_key": {}, }, }, }, }, "/whitelist": { "get": { Tags: []string{"辅助接口"}, Summary: "接口白名单", Description: "接口白名单是指`不需要任何令牌`,可直接访问的接口,请前往在线链接查看最新列表", OperationID: "whitelist", Responses: map[int]DocPathResponse{ 200: { Description: "查询接口白名单成功", Content: map[string]DocPathContentItem{ "text/plain": { Schema: DocPathSchema{Type: "string"}, }, }, }, }, }, }, } for _, m := range validMeta { key := strings.ToLower(path.Join(GetModPrefix(m.ModCode), fmt.Sprintf("/%s", m.Name))) items := make(DocPathItems) displayName := m.DisplayName if displayName == "" { displayName = m.Name } if m.RestDesc.Create { items["post"] = DocPathItem{ Tags: []string{m.Name}, Summary: fmt.Sprintf("新增%s", displayName), Description: "注意:\n1. 如需批量新增,请传递对象数组\n1. 当你请求体为对象格式时,返回数据也为对象格式\n1. 当你请求体为对象数组时,返回数据也为对象数组", OperationID: fmt.Sprintf("create%s", m.Name), RequestBody: DocPathRequestBody{ Required: true, Description: fmt.Sprintf("%s对象", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), }, }, }, }, Responses: map[int]DocPathResponse{ 200: { Description: fmt.Sprintf("新增%s成功", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), }, }, }, }, }, Security: []DocPathItemSecurity{ map[string][]string{ "api_key": {}, }, }, } } if m.RestDesc.Delete { items["delete"] = DocPathItem{ Tags: []string{m.Name}, Summary: fmt.Sprintf("删除%s", displayName), Description: "注意:\n如需批量删除,请指定multi=true", OperationID: fmt.Sprintf("delete%s", m.Name), Parameters: []DocPathParameter{ { Name: "cond", In: "query", Required: true, Description: "删除条件,JSON格式的字符串", Schema: DocPathSchema{ Type: "string", }, }, { Name: "multi", In: "query", Description: "是否批量删除", Schema: DocPathSchema{ Type: "boolean", }, }, }, Responses: map[int]DocPathResponse{ 200: { Description: fmt.Sprintf("删除%s成功", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), }, }, }, }, }, Security: []DocPathItemSecurity{ map[string][]string{ "api_key": {}, }, }, } } if m.RestDesc.Update { items["put"] = DocPathItem{ Tags: []string{m.Name}, Summary: fmt.Sprintf("修改%s", displayName), Description: "注意:\n如需批量修改,请指定multi=true", OperationID: fmt.Sprintf("update%s", m.Name), RequestBody: DocPathRequestBody{ Required: true, Description: fmt.Sprintf("%s对象", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Type: "object", Properties: map[string]DocPathSchema{ "cond": { Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), Required: true, }, "doc": { Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), Required: true, }, "multi": { Type: "boolean", }, }, }, }, }, }, Responses: map[int]DocPathResponse{ 200: { Description: fmt.Sprintf("修改%s成功", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), }, }, }, }, }, Security: []DocPathItemSecurity{ map[string][]string{ "api_key": {}, }, }, } } if m.RestDesc.Query { items["get"] = DocPathItem{ Tags: []string{m.Name}, Summary: fmt.Sprintf("查询%s", displayName), OperationID: fmt.Sprintf("query%s", m.Name), Parameters: []DocPathParameter{ { Name: "range", In: "query", Description: "查询数据范围,分页(PAGE)或全量(ALL)", Schema: DocPathSchema{ Type: "string", Enum: []interface{}{ "PAGE", "ALL", }, Default: "PAGE", }, }, { Name: "cond", In: "query", Description: fmt.Sprintf("查询条件,%s对象的JSON字符串", displayName), Schema: DocPathSchema{ Type: "string", }, }, { Name: "sort", In: "query", Description: "排序字段,多字段排序以英文逗号分隔,逆序以负号开头", Schema: DocPathSchema{ Type: "string", }, }, { Name: "project", In: "query", Description: "查询字段,注意字段依然返回,只是不查询", Schema: DocPathSchema{ Type: "string", }, }, { Name: "page", In: "query", Description: "当前页码(仅PAGE模式有效)", Schema: DocPathSchema{ Type: "integer", Default: 1, }, }, { Name: "size", In: "query", Description: "每页条数(仅PAGE模式有效)", Schema: DocPathSchema{ Type: "integer", Default: 30, }, }, }, Responses: map[int]DocPathResponse{ 200: { Description: fmt.Sprintf("查询%s成功", displayName), Content: map[string]DocPathContentItem{ "application/json": { Schema: DocPathSchema{ Type: "object", Properties: map[string]DocPathSchema{ "list": { Type: "array", Items: &DocPathSchema{ Ref: fmt.Sprintf("#/components/schemas/%s", m.Name), }, }, "totalrecords": { Type: "integer", Description: "当前查询条件下的总记录数", }, "totalpages": { Type: "integer", Description: "当前查询条件下的总页数(仅PAGE模式存在)", }, }, }, }, }, }, }, Security: []DocPathItemSecurity{ map[string][]string{ "api_key": {}, }, }, } } if len(items) > 0 { paths[key] = items } } return }(), Components: DocComponent{ Schemas: func() (schemas map[string]DocComponentSchema) { schemas = make(map[string]DocComponentSchema) em := EnumMap() for _, m := range validMeta { props := make(map[string]DocSchemaProperty) for _, f := range m.Fields { prop := DocSchemaProperty{} if f.Name != "" { prop.Title = f.Name } if f.IsRef { if f.IsArray { prop.Type = "array" prop.Items = &DocSchemaProperty{ Ref: fmt.Sprintf("#/components/schemas/%s", f.Type), } } else { prop.Ref = fmt.Sprintf("#/components/schemas/%s", f.Type) } } else { prop.Type = f.Type } if f.Enum != "" && em[f.Enum] != nil { for value, _ := range em[f.Enum].Values { prop.Enum = append(prop.Enum, value) } } props[f.Code] = prop } schemas[m.Name] = DocComponentSchema{ Type: "object", Properties: props, } } return }(), SecuritySchemes: map[string]DocSecurityScheme{ "api_key": { Type: "apiKey", Name: "api_key", In: "header", }, }, }, } yml := doc.Marshal() if json { data, err := yaml.YAMLToJSON([]byte(yml)) if err != nil { return c.STDErr(err, "model_docs_failed") } json := string(data) valueCacheMap.Store(hashKeyJSON, json) c.String(http.StatusOK, json) } else { valueCacheMap.Store(hashKeyYAML, yml) c.String(http.StatusOK, yml) } return nil }, }
ModelDocsRoute
var ModelWSRoute = RouteInfo{ Name: "模型变更通知WebSocket接口", Method: "GET", Path: "/model/ws", HandlerFunc: func(c *Context) *STDReply { conn, err := modelUpgrader.Upgrade(c.Writer, c.Request, nil) if err != nil { ERROR("websocket.upgrade: %v", err) return nil } defer func() { if _, ok := modelWSConns.Load(conn); ok { modelWSConns.Delete(conn) } conn.Close() INFO("websocket.close: %p", conn) }() modelWSConns.Store(conn, conn) INFO("websocket.connect: %p", conn) for { mt, message, err := conn.ReadMessage() if err != nil { ERROR(err) break } INFO("websocket.recv: %s", message) err = conn.WriteMessage(mt, message) if err != nil { ERROR(err) break } } return nil }, }
ModelWSRoute
var OrgLoginableRoute = RouteInfo{ Name: "查询可登录组织", Method: "GET", Path: "/org/loginable", IntlMessages: map[string]string{ "org_query_failed": "Query organization failed", }, HandlerFunc: func(c *Context) *STDReply { c.IgnoreAuth() data, err := GetLoginableOrgs(c, c.SignInfo.UID) if err != nil { return c.STDErr(err, "org_query_failed") } return c.STD(data) }, }
OrgLoginableRoute
var OrgSwitchRoute = RouteInfo{ Name: "切换当前登录组织", Method: "POST", Path: "/org/switch", IntlMessages: map[string]string{ "org_switch_failed": "Switching organization failed", }, HandlerFunc: func(c *Context) *STDReply { var body struct { ActOrgID uint } if err := c.ShouldBindJSON(&body); err != nil { return c.STDErr(err, "org_switch_failed") } err := c.IgnoreAuth().DB(). Model(&User{ID: c.SignInfo.UID}). Update(User{ActOrgID: body.ActOrgID}).Error if err != nil { return c.STDErr(err, "org_switch_failed") } return c.STDOK() }, }
OrgSwitchRoute
var Recovery gin.HandlerFunc
Recovery defined kuu.Engine recovery from panic Rewrite `Recovery` if you need Tag: 在rest不处理error,除非业务需求(如事物),直接抛出来
var RoleUserAssigns = RouteInfo{ Name: "查询角色关联用户", Method: "GET", Path: "/role/user_assigns/:roleid", IntlMessages: map[string]string{ "role_users_assigns_failed": "Role assigns users query failed", }, HandlerFunc: func(c *Context) *STDReply { raw := c.Param("roleid") if raw == "" { return c.STDErr(errors.New("roleid is required"), "role_users_assigns_failed") } id := ParseID(raw) var userids []uint DB().Model(&RoleAssign{}).Where("role_id = ?", id).Pluck("user_id", &userids) var users []User DB().Model(&User{}).Where("id in (?)", userids).Find(&users) var result []map[string]any for _, user := range users { item := map[string]any{ "ID": user.ID, "Name": user.Name, "Username": user.Username, "Mobile": user.Mobile, "Disable": user.Disable, "CreatedAt": user.CreatedAt, } if os.Getenv("HIDDEN_MOBILE") == "true" { item["Mobile"] = hideMobile(user.Mobile) } result = append(result, item) } return c.STD(result) }, }
RoleUserAssigns
var RoleUserAssignsList = RouteInfo{ Name: "查询角色关联用户", Method: "GET", Path: "/role/user_assigns_list", IntlMessages: map[string]string{ "role_users_assigns_failed": "Role assigns users query failed", }, HandlerFunc: func(c *Context) *STDReply { var roles []Role DB().Model(&Role{}).Find(&roles) return c.STDOK() }, }
RoleUserAssigns
var SetPayloadAttrs = func(payload jwt.MapClaims, user *User) jwt.MapClaims {
return payload
}
SetPayloadAttrs
var TriggerRepeatEvent = RouteInfo{ Name: "触发执行可重复事件", Method: "GET", Path: "/TriggerRepeatEvent", HandlerFunc: func(c *Context) *STDReply { c.IgnoreAuth() name := c.Query("name") q := DB().Model(&RepeatEvent{}).Where("status = '0' and next_time <= ?", time.Now()) if name != "" { q = q.Where("name = ?", name) } var repeatEvents []RepeatEvent q.Find(&repeatEvents) for _, event := range repeatEvents { context := &REContext{Event: event} JSONParse(context.Event.Data, &context.Data) intervals := strings.Split(event.RetryInterval, "/") context.Max = len(intervals) context.Current = event.RetryCount + 1 if processer, has := repeatEventProcesserMap[event.Name]; has { go processRepeatEvent(processer, context) } } return c.STDOK() }, }
var UploadRoute = RouteInfo{ Name: "默认文件上传接口", Method: "POST", Path: "/upload", IntlMessages: map[string]string{ "upload_failed": "Upload file failed", }, HandlerFunc: func(c *Context) *STDReply { var ( save2db = true ) if v, ok := c.GetPostForm("save2db"); ok { if b, err := strconv.ParseBool(v); err == nil { save2db = b } } extra, err := getFileExtraData(c) if err != nil { return c.STDErr(err, "upload_failed") } fh, err := c.FormFile("file") if err != nil { return c.STDErr(err, "upload_failed") } file, err := SaveUploadedFile(fh, save2db, extra) if err != nil { return c.STDErr(err, "upload_failed") } return c.STD(file) }, }
UploadRoute
var UserMenusRoute = RouteInfo{ Name: "查询用户菜单", Method: "GET", Path: "/user/menus", IntlMessages: map[string]string{ "user_menus_failed": "User menus query failed", }, HandlerFunc: func(c *Context) *STDReply { var menus MenuList if err := c.DB().Find(&menus).Error; err != nil { return c.STDErr(err, "user_menus_failed") } // 补全父级菜单 var total MenuList if err := c.IgnoreAuth().DB().Find(&total).Error; err != nil { return c.STDErr(err, "user_menus_failed") } if c.PrisDesc.HasPermission("sys_menu") { sort.Sort(total) return c.STD(total) } var ( codeMap = make(map[string]Menu) existsMap = make(map[uint]bool) finded = make(map[uint]bool) ) for _, item := range total { codeMap[item.Code] = item } for _, item := range menus { existsMap[item.ID] = true } var fall func(result MenuList) MenuList fall = func(result MenuList) MenuList { recall := false for _, item := range result { if !finded[item.ID] { pitem := codeMap[item.ParentCode.String] if item.ParentCode.String != "" && pitem.ID != 0 && !existsMap[pitem.ID] { result = append(result, pitem) recall = true existsMap[pitem.ID] = true } finded[item.ID] = true } } if recall { return fall(result) } return result } menus = fall(menus) if strings.ToLower(c.DefaultQuery("default", "true")) == "false" { var filtered MenuList for _, item := range menus { if item.Code != "default" { filtered = append(filtered, item) } } menus = filtered } sort.Sort(menus) return c.STD(menus) }, }
UserMenusRoute
var UserRoleAssigns = RouteInfo{ Name: "查询用户已分配角色", Method: "GET", Path: "/user/role_assigns/:uid", IntlMessages: map[string]string{ "role_assigns_failed": "User roles query failed", }, HandlerFunc: func(c *Context) *STDReply { raw := c.Param("uid") if raw == "" { return c.STDErr(errors.New("UID is required"), "role_assigns_failed") } uid := ParseID(raw) user, err := GetUserWithRoles(uid) if err != nil { return c.STDErr(err, "role_assigns_failed") } return c.STD(user.RoleAssigns) }, }
UserRoleAssigns
var ValidRoute = RouteInfo{ Name: "令牌有效性验证接口", Method: "POST", Path: "/valid", IntlMessages: map[string]string{ "acc_invalid_token": "Invalid token.", }, HandlerFunc: func(c *Context) *STDReply { // 查询用户 var user User if err := c.IgnoreAuth().DB().Select("lang, act_org_id").First(&user, "id = ?", c.SignInfo.UID).Error; err != nil { return c.STDErr(err, "acc_invalid_token") } if user.Lang == "" { user.Lang = c.Lang() } c.SetCookie(LangKey, user.Lang, ExpiresSeconds, "/", "", false, true) c.SignInfo.Payload["Lang"] = user.Lang c.SignInfo.Payload["ActOrgID"] = c.PrisDesc.ActOrgID c.SignInfo.Payload["ActOrgCode"] = c.PrisDesc.ActOrgCode c.SignInfo.Payload["ActOrgName"] = c.PrisDesc.ActOrgName c.SignInfo.Payload[TokenKey] = c.SignInfo.Token if c.PrisDesc != nil { c.SignInfo.Payload["Permissions"] = c.PrisDesc.Permissions c.SignInfo.Payload["RolesCode"] = c.PrisDesc.RolesCode } return c.STD(c.SignInfo.Payload) }, }
ValidRoute
var WhitelistRoute = RouteInfo{ Name: "查询白名单列表", Method: "GET", Path: "/whitelist", HandlerFunc: func(c *Context) *STDReply { var list []string for _, item := range Whitelist { if v, ok := item.(string); ok { list = append(list, v) } else if v, ok := item.(*regexp.Regexp); ok { list = append(list, v.String()) } } return c.STD(list) }, }
WhitelistRoute
Functions ¶
func AESCBCEncrypt ¶
AESCBCEncrypt 填充秘钥key的16位(24、32分别对应AES-128、AES-192或AES-256)
func AddDefaultIntlMessage ¶
func AddJob ¶
func AddJob(spec string, name string, cmd func(c *JobContext)) (cron.EntryID, error)
AddJob
func AddPresetIntlMessage ¶
func AddWhitelist ¶
func AddWhitelist(rules ...interface{})
AddWhitelist support string and *regexp.Regexp.
func BatchInsert ¶
BatchInsert
func BeforeUse ¶
func BeforeUse(handlers ...HandlerFunc)
func BeforeUseGin ¶
func BeforeUseGin(handlers ...gin.HandlerFunc)
func CompareHashAndPassword ¶
CompareHashAndPassword 密码比对
func ContainsCache ¶
ContainsCache
func DEBUGWithFields ¶
func DecodedToken ¶
DecodedToken
func ERRORWithFields ¶
func EncodedToken ¶
EncodedToken
func FATALWithFields ¶
func FindReadableMessageIDs ¶
func FindUnreadMessageIDs ¶
func FindUnreadMessagesCount ¶
func FlatValidatorErrors ¶
func FlatValidatorErrors(validatorErrors govalidator.Errors) []govalidator.Error
FlatValidatorErrors
func GenerateCaptcha ¶
GenerateCaptcha create a digit captcha.
func GenerateFromPassword ¶
GenerateFromPassword 生成新密码
func GetDataScopeWheres ¶
func GetDataScopeWheres(scope *gorm.Scope, desc *PrivilegesDesc, orgIDs []uint, personalOrgIDMap map[uint]Org) (sqls []string, attrs []interface{})
GetDataScopeWheres
func GetEnumLabel ¶
func GetIntlMessages ¶
func GetIntlMessagesByLang ¶
func GetMessageCommonDB ¶
func GetPagination ¶
Pagination
func GetPresetIntlMessage ¶
func GetUploadDir ¶
func GetUploadDir() string
func HasPrefixCache ¶
HasPrefixCache
func HasSuffixCache ¶
HasSuffixCache
func INFOWithFields ¶
func LoadParmsFroSubApp ¶
func LoadParmsFroSubApp()
func NewCaptcha ¶
func NewCaptcha() *base64Captcha.Captcha
NewCaptcha creates a captcha instance from driver and store
func NewIntlError ¶
func NewValidError ¶
NewValidError generate a new error for a model's field
func OmitFields ¶
OmitFields
func PANICWithFields ¶
func PRINTWithFields ¶
func PSubscribeCache ¶
PSubscribeCache
func ParseExcelFromFileHeader ¶
func ParseExcelFromFileHeader(fh *multipart.FileHeader, index int, sheetName ...string) (rows [][]string, err error)
ParseExcelFromFileHeader
func RSADecrypt ¶
RSADecrypt 私钥解密(此处传入公钥的作用是为了解析不限长度的明文)
func RSASignWithSha256 ¶
RSASignWithSha256 签名
func RSAVerySignWithSha256 ¶
RSAVerySignWithSha256 验签
func ReadData ¶
read data
Example ¶
file, err := excelize.OpenFile("data.xlsx") if err != nil { panic(err) } headers := Headers{ { Label: "字段0", Field: "Field0", Index: 0, }, { Label: "字段3", Field: "Field3", Index: 3, }, { Label: "字段1", Field: "Field1", Index: 1, }, { Label: "字段2", Field: "Field2", Index: 2, }, } sheet := file.GetSheetName(1) list, err := ReadData(file, sheet, headers) if err != nil { panic(err) } for _, m := range list { fmt.Println(m) }
Output:
func RegisterBizHook ¶
模型名称:BizBeforeCreate
func RegisterGormHook ¶
模型名称:BeforeCreate
func RegisterImportCallback ¶
func RegisterImportCallback(callback *ImportCallback)
RegisterImportCallback 注册导入回调
func RegisterRepeatEvent ¶
ReigsterRepeatEvent
func RegisterRepeatEventProcesser ¶
func RegisterRepeatEventProcesser(name string, processer RepeatEventProcesser)
ReigsterRepeatEventProcesser
func ReloadIntlMessages ¶
func RunAllRunAfterJobs ¶
func RunAllRunAfterJobs()
func SetCacheString ¶
SetCacheString
func SetData ¶
set header and data row
Example ¶
headers := Headers{ { Label: "字段0", Field: "Field0", Index: 0, }, { Label: "字段3", Field: "Field3", Index: 3, }, { Label: "字段1", Field: "Field1", Index: 1, }, { Label: "字段2", Field: "Field2", Index: 2, }, } list := []map[string]interface{}{ { "Field0": "221", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2211", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2212", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2213", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2214", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2215", "Field1": "221", "Field2": "221", "Field3": "221", }, { "Field0": "2216", "Field1": "221", "Field2": "221", "Field3": "221", }, } file2 := excelize.NewFile() SetData(file2, "Sheet1", headers, list) file2.SaveAs("data.xlsx")
Output:
func SetHeader ¶
only set header label
Example ¶
var headers = Headers{} for i := 0; i < 500; i++ { h := Header{ Label: fmt.Sprintf("Label%d", i), Field: fmt.Sprintf("Field%d", i), Index: i, } v := h.GetExcelCol() fmt.Println(v) headers = append(headers, h) } file := excelize.NewFile() SetHeader(file, "Sheet1", headers) file.SaveAs("500-col-headers.xlsx")
Output:
func SetUrlQuery ¶
SetUrlQuery
func SubscribeCache ¶
SubscribeCache
func TimeFromExcelTime ¶
timeFromExcelTime provides a function to convert an excelTime representation (stored as a floating point number) to a time.Time.
func TimeToExcelTime ¶
timeToExcelTime provides a function to convert time to Excel time.
func VerifyCaptcha ¶
VerifyCaptcha Verify captcha value.
func VerifyCaptchaWithClear ¶
VerifyCaptchaWithClear Verify captcha value.
func WARNWithFields ¶
Types ¶
type ASCIISigner ¶
type ASCIISigner struct { Value interface{} Alg string OmitKeys []string IncludeEmpty bool PrintRaw bool FieldString func(string, interface{}, bool) string Prefix string Suffix string ToUpper bool }
ASCIISigner
type AuthProcessor ¶
type AuthProcessor interface { AllowCreate(AuthProcessorDesc) error AddWritableWheres(AuthProcessorDesc) error AddReadableWheres(AuthProcessorDesc) error }
AuthProcessor
type AuthProcessorDesc ¶
type AuthProcessorDesc struct { Meta *Metadata SubDocIDNames []string Scope *gorm.Scope PrisDesc *PrivilegesDesc HasCreatedByIDField bool HasOrgIDField bool CreatedByIDField *gorm.Field OrgIDFieldField *gorm.Field CreatedByID uint OrgID uint }
AuthProcessorDesc
func GetAuthProcessorDesc ¶
func GetAuthProcessorDesc(scope *gorm.Scope, desc *PrivilegesDesc) (auth AuthProcessorDesc)
GetAuthProcessorDesc
type BatchInsertItem ¶
type BatchInsertItem struct { SQL string Vars []interface{} }
BatchInsertItem
type BizPreloadInterface ¶
type BizQueryResult ¶
type BizQueryResult struct { Cond map[string]interface{} `json:"cond,omitempty"` Project string `json:"project,omitempty"` Preload string `json:"preload,omitempty"` Sort string `json:"sort,omitempty"` Range string `json:"range,omitempty"` Page int `json:"page,omitempty"` Size int `json:"size,omitempty"` TotalRecords int `json:"totalrecords,omitempty"` TotalPages int `json:"totalpages,omitempty"` List interface{} `json:"list,omitempty"` }
BizQueryResult
type BizUpdateParams ¶
type BizUpdateParams struct { All bool Multi bool Cond map[string]interface{} Doc map[string]interface{} }
BizUpdateParams
type Cache ¶
type Cache interface { SetString(string, string, ...time.Duration) HasPrefix(string, int) map[string]string HasSuffix(string, int) map[string]string Contains(string, int) map[string]string GetString(string) string SetInt(string, int, ...time.Duration) GetInt(string) int Incr(string) int Del(...string) Close() HGetAll(string) map[string]string HGet(string, string) string HSet(string, ...string) Publish(channel string, message interface{}) error Subscribe(channels []string, handler func(string, string)) error PSubscribe(patterns []string, handler func(string, string)) error }
Cache todo
var DefaultCache Cache
DefaultCache
type CacheBolt ¶
type CacheBolt struct {
// contains filtered or unexported fields
}
CacheBolt
func (*CacheBolt) PSubscribe ¶
type CacheRedis ¶
type CacheRedis struct {
// contains filtered or unexported fields
}
CacheRedis
func (*CacheRedis) Contains ¶
func (c *CacheRedis) Contains(rawKey string, limit int) map[string]string
Contains
func (*CacheRedis) HGet ¶
func (c *CacheRedis) HGet(key, field string) string
func (*CacheRedis) HSet ¶
func (c *CacheRedis) HSet(key string, values ...string)
func (*CacheRedis) HasPrefix ¶
func (c *CacheRedis) HasPrefix(rawKey string, limit int) map[string]string
HasPrefix
func (*CacheRedis) HasSuffix ¶
func (c *CacheRedis) HasSuffix(rawKey string, limit int) map[string]string
HasSuffix
func (*CacheRedis) PSubscribe ¶
func (c *CacheRedis) PSubscribe(patterns []string, handler func(string, string)) error
func (*CacheRedis) Publish ¶
func (c *CacheRedis) Publish(channel string, message interface{}) error
func (*CacheRedis) SetInt ¶
func (c *CacheRedis) SetInt(rawKey string, val int, expiration ...time.Duration)
SetInt
type CallbackProcessor ¶
type CallbackProcessor struct {
// contains filtered or unexported fields
}
CallbackProcessor contains callback informations
func (*CallbackProcessor) After ¶
func (cp *CallbackProcessor) After(callbackName string) *CallbackProcessor
After insert a new callback after callback `callbackName`, refer `Callbacks.Create`
func (*CallbackProcessor) Before ¶
func (cp *CallbackProcessor) Before(callbackName string) *CallbackProcessor
Before insert a new callback before callback `callbackName`, refer `Callbacks.Create`
func (*CallbackProcessor) Get ¶
func (cp *CallbackProcessor) Get(callbackName string) (callback func(scope *Scope))
Get registered callback
db.Callback().Create().Get("gorm:create")
func (*CallbackProcessor) Register ¶
func (cp *CallbackProcessor) Register(callbackName string, callback func(scope *Scope))
Register a new callback, refer `Callbacks.Create`
func (*CallbackProcessor) Remove ¶
func (cp *CallbackProcessor) Remove(callbackName string)
Remove a registered callback
db.Callback().Create().Remove("gorm:update_time_stamp_when_create")
func (*CallbackProcessor) Replace ¶
func (cp *CallbackProcessor) Replace(callbackName string, callback func(scope *Scope))
Replace a registered callback with new callback
db.Callback().Create().Replace("gorm:update_time_stamp_when_create", func(*Scope) { scope.SetColumn("Created", now) scope.SetColumn("Updated", now) })
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub.
type CondDesc ¶
type CondDesc struct { AndSQLs []string AndAttrs []interface{} OrSQLs []string OrAttrs []interface{} }
CondDesc
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) DefaultGetBool ¶
DefaultGetBool returns the value associated with the key as a boolean.
func (*Config) DefaultGetFloat64 ¶
DefaultGetInt returns the value associated with the key as a float64.
func (*Config) DefaultGetInt ¶
DefaultGetInt returns the value associated with the key as a integer.
func (*Config) DefaultGetString ¶
DefaultGetString returns the value associated with the key as a string.
func (*Config) GetFloat32 ¶
GetFloat64 returns the value associated with the key as a float32.
func (*Config) GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func (*Config) GetInterface ¶
GetInterface returns the value associated with the key.
func (*Config) LoadFromParams ¶
type Context ¶
type Context struct { *gin.Context SignInfo *SignContext PrisDesc *PrivilegesDesc RoutineCaches RoutineCaches RouteInfo *RouteInfo // contains filtered or unexported fields }
Context
func (*Context) Abort ¶
c.Abort(data, localeMessageName, defaultLocaleMessageText, localeMessageValues)
func (*Context) AbortErr ¶
c.AbortErr(err, localeMessageName, defaultLocaleMessageText, localeMessageValues)
func (*Context) AbortErrWithCode ¶
c.AbortErrWithCode(errData, code, localeMessageName, defaultLocaleMessageText, localeMessageValues)
func (*Context) DecodedContext ¶
func (c *Context) DecodedContext() (sign *SignContext, err error)
DecodedContext
func (*Context) FormatMessage ¶
func (*Context) GetIntlMessages ¶
func (*Context) GetPagination ¶
GetPagination
func (*Context) GetRoutineCache ¶
GetValue
func (*Context) ParseCond ¶
func (c *Context) ParseCond(model interface{}, db *gorm.DB) (map[string]interface{}, *gorm.DB, error)
ParseCond
func (*Context) RequestCode ¶
func (*Context) STD ¶
STD render a JSON body with code(default is 0), data and message.
c.STD(data, localeMessageName, defaultLocaleMessageText, localeMessageValues)
Examples:
c.STD(data) c.STD(data, "hello") c.STD(data, "hello", "Hello") c.STD(data, "welcome", "Welcome {{name}}", mot.D{"name": "xxx"})
func (*Context) STDErr ¶
STDErr render a JSON body with error message, error code(default is -1) and error detail.
c.STDErr(err, localeMessageName, defaultLocaleMessageText, localeMessageValues)
Examples:
c.STDErr(err, "hello") c.STDErr(err, "hello", "Hello") c.STDErr(err, "welcome", "Welcome {{name}}", D{"name": "xxx"})
func (*Context) STDErrWithCode ¶
STDErrWithCode render a JSON body with error message, custom error code and error detail.
c.STDErrWithCode(errData, code, localeMessageName, defaultLocaleMessageText, localeMessageValues)
Examples:
c.STDErrWithCode(errData, 555, "hello") c.STDErrWithCode(errData, 501, "hello", "Hello") c.STDErrWithCode(errData, 500, "welcome", "Welcome {{name}}", D{"name": "xxx"})
func (*Context) SetRoutineCache ¶
SetValue
type CreateOrgArgs ¶
type CreateOrgReply ¶
type CreateOrgReply struct { OrgID uint Org *Org AdminUID uint AdminUser *User GeneratedPlaintextPassword string }
func CreateOrg ¶
func CreateOrg(args *CreateOrgArgs) (reply *CreateOrgReply, err error)
type DBTypeRepairer ¶
type DBTypeRepairer interface {
RepairDBTypes()
}
type DataPrivileges ¶
type DataPrivileges struct { Model `rest:"*" displayName:"角色数据权限"` ExtendField RoleID uint `name:"角色ID"` TargetOrgID uint `name:"目标组织ID"` ReadableRange string `name:"可读范围" enum:"DataScope"` WritableRange string `name:"可写范围" enum:"DataScope"` }
DataPrivileges
func (*DataPrivileges) BeforeSave ¶
func (m *DataPrivileges) BeforeSave(scope *gorm.Scope)
BeforeSave
type DefaultAuthProcessor ¶
type DefaultAuthProcessor struct{}
DefaultAuthProcessor
func (*DefaultAuthProcessor) AddReadableWheres ¶
func (por *DefaultAuthProcessor) AddReadableWheres(auth AuthProcessorDesc) (err error)
AddReadableWheres
func (*DefaultAuthProcessor) AddWritableWheres ¶
func (por *DefaultAuthProcessor) AddWritableWheres(auth AuthProcessorDesc) (err error)
AddWritableWheres
func (*DefaultAuthProcessor) AllowCreate ¶
func (por *DefaultAuthProcessor) AllowCreate(auth AuthProcessorDesc) (err error)
AllowCreate
type Doc ¶
type Doc struct { Openapi string Info DocInfo Servers []DocServer Tags []DocTag Paths map[string](DocPathItems) Components DocComponent }
type DocComponent ¶
type DocComponent struct { Schemas map[string]DocComponentSchema SecuritySchemes map[string]DocSecurityScheme `yaml:"securitySchemes"` }
type DocComponentSchema ¶
type DocComponentSchema struct { Required []string Type string Properties map[string]DocSchemaProperty }
type DocInfo ¶
type DocInfo struct { Title string Description string Contact DocInfoContact Version string }
type DocInfoContact ¶
type DocInfoContact struct {
Email string
}
type DocPathContentItem ¶
type DocPathContentItem struct {
Schema DocPathSchema
}
type DocPathItem ¶
type DocPathItem struct { Tags []string Summary string Description string OperationID string `yaml:"operationId"` RequestBody DocPathRequestBody `yaml:"requestBody"` Responses map[int]DocPathResponse Parameters []DocPathParameter Deprecated bool Security []DocPathItemSecurity }
type DocPathItemSecurity ¶
type DocPathItems ¶
type DocPathItems map[string]DocPathItem
type DocPathParameter ¶
type DocPathRequestBody ¶
type DocPathRequestBody struct { Description string Content map[string]DocPathContentItem Required bool }
type DocPathResponse ¶
type DocPathResponse struct { Description string Content map[string]DocPathContentItem }
type DocPathSchema ¶
type DocPathSchema struct { Type string Description string Format string Ref string `yaml:"$ref"` Properties map[string]DocPathSchema Items *DocPathSchema Enum []interface{} Default interface{} Required bool }
type DocSchemaProperty ¶
type DocSchemaProperty struct { Title string Type string Ref string `yaml:"$ref"` Properties *DocPathSchema Items *DocSchemaProperty Format string Enum []interface{} Default interface{} }
type DocSecurityScheme ¶
type Engine ¶
Engine
func (*Engine) Any ¶
func (app *Engine) Any(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.Any
func (*Engine) DELETE ¶
func (app *Engine) DELETE(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.DELETE
func (*Engine) GET ¶
func (app *Engine) GET(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.GET
func (*Engine) Group ¶
func (app *Engine) Group(relativePath string, handlers ...HandlerFunc) *gin.RouterGroup
Overrite r.Group
func (*Engine) HEAD ¶
func (app *Engine) HEAD(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.HEAD
func (*Engine) Handle ¶
func (app *Engine) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.Handle
func (*Engine) OPTIONS ¶
func (app *Engine) OPTIONS(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.OPTIONS
func (*Engine) PATCH ¶
func (app *Engine) PATCH(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.PATCH
func (*Engine) POST ¶
func (app *Engine) POST(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.POST
func (*Engine) PUT ¶
func (app *Engine) PUT(relativePath string, handlers ...HandlerFunc) gin.IRoutes
Overrite r.PUT
func (*Engine) RegisterWhitelist ¶
func (app *Engine) RegisterWhitelist(rules ...interface{})
RegisterWhitelist
func (*Engine) Use ¶
func (app *Engine) Use(handlers ...HandlerFunc) *Engine
type EnumDesc ¶
type EnumDesc struct { ClassCode string ClassName string Values map[interface{}]string `json:"-"` Items []EnumItem `json:"Values"` }
func GetEnumItem ¶
type EventLog ¶
type EventLog struct { Model `rest:"*" displayName:"事件日志"` EventID string `name:"事件ID(UUID)" gorm:"NOT NULL"` EventTime int64 `name:"事件时间" gorm:"NOT NULL"` SourceIP string `name:"来源IP" gorm:"NOT NULL"` UserID uint `name:"操作人ID" gorm:"NOT NULL"` UserName string `name:"操作人名称" gorm:"NOT NULL"` UserEmailAddress string `name:"操作人邮箱"` UserPhoneNumber string `name:"操作人手机"` EventClass string `name:"事件分类" gorm:"NOT NULL" enum:"EventLogClass"` EventSubject string `name:"事件主题" gorm:"NOT NULL"` EventSummary string `name:"事件摘要" gorm:"NOT NULL"` EventLabels []EventLogLabel `name:"关联事件标签"` EventData string `name:"事件详情(JSON-String)"` }
type EventLogLabel ¶
type EventLogLabel struct { Model `rest:"*" displayName:"事件日志标签"` EventLogID uint `name:"关联事件日志ID" gorm:"NOT NULL"` EventLog *EventLog `name:"关联事件日志"` EventClass string `name:"事件分类" gorm:"NOT NULL;INDEX:event_log_label" enum:"EventLogClass"` LabelKey string `name:"标签名" gorm:"NOT NULL;INDEX:event_log_label"` LabelValue string `name:"标签值" gorm:"NOT NULL;INDEX:event_log_label"` }
type ExtendField ¶
type ExtendField struct { Def1 uint `name:"扩展字段1(默认字段)"` Def2 string `name:"扩展字段2(默认字段)" gorm:"type:text"` Def3 string `name:"扩展字段3(默认字段)"` Def4 string `name:"扩展字段4(默认字段)"` Def5 string `name:"扩展字段5(默认字段)"` }
ExtendField
type File ¶
type File struct { Model `rest:"*" displayName:"文件"` ExtendField Class string `name:"文件分类"` OwnerID uint `name:"归属数据ID"` OwnerType string `name:"归属数据类型"` UID string `name:"文件唯一ID" json:"uid" gorm:"not null"` Type string `name:"文件Mine-Type" json:"type" gorm:"not null"` Size int64 `name:"文件大小" json:"size" gorm:"not null"` Name string `name:"文件名称" json:"name" gorm:"not null"` URL string `name:"文件下载路径" json:"url" gorm:"not null"` Path string `name:"文件存储路径" json:"path" gorm:"not null"` }
File
func SaveUploadedFile ¶
func SaveUploadedFile(fh *multipart.FileHeader, save2db bool, extraData ...*File) (f *File, err error)
SaveUploadedFile
type GenTokenDesc ¶
type HandlerFunc ¶
HandlerFunc defines the handler used by ok middleware as return value.
type Header ¶
type Header struct { Label string // header column name Field string // fieldname Index int // index }
func (*Header) GetExcelAxis ¶
get excel axis e.g: A1, A2, A4
func (*Header) GetExcelCol ¶
get excel column name,support 26*26=676 columns。 e.g: A,B,C,D,E org AA, AB
type Headers ¶
type Headers []Header
func (Headers) GetColByField ¶
get column by fieldname
func (Headers) GetColByIndex ¶
get column by index
type HookHandler ¶
type HookHandler func(args ...interface{}) error
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
type IPInfo ¶
type IPInfo struct { IP string `json:"ip"` Country string `json:"country"` CountryID string `json:"country_id"` Area string `json:"area"` Region string `json:"region"` City string `json:"city"` ISP string `json:"isp"` }
IPInfo
type ImportCallback ¶
type ImportCallback struct { Channel string Description string TemplateGenerator func(*Context) (string, []string) Validator ImportCallbackValidator Processor ImportCallbackProcessor }
type ImportCallbackProcessor ¶
type ImportCallbackProcessor func(c *Context, rows [][]string) *ImportCallbackResult
ImportCallbackProcessor
type ImportCallbackResult ¶
type ImportCallbackResult struct { Feedback []ImportFeedback Message string Error error Extra map[string]interface{} }
ImportCallbackResult
type ImportCallbackValidator ¶
ImportCallbackValidator
type ImportContext ¶
type ImportFeedback ¶
type ImportRecord ¶
type ImportRecord struct { Model `rest:"*" displayName:"导入记录"` Sync bool `name:"是否同步执行"` ImportSn string `name:"批次编号" sql:"index"` Context string `name:"导入时上下文数据" gorm:"type:text"` Channel string `name:"导入渠道"` Data string `name:"导入数据([][]string)" gorm:"type:text"` Feedback string `name:"反馈记录([]string)" gorm:"type:text"` Status string `name:"导入状态" enum:"ImportStatus"` Message string `name:"导入结果"` Error string `name:"错误详情"` Extra string `name:"额外数据(JSON)" gorm:"type:text"` }
ImportRecord
func CallImportCallback ¶
func CallImportCallback(c *Context, info *ImportRecord) (*ImportRecord, error)
CallImportCallback
type IntlMessagesOptions ¶
type Job ¶
type Job struct { Spec string `json:"spec" valid:"required"` Cmd func(c *JobContext) `json:"-,omitempty"` Code string `json:"code"` Name string `json:"name" valid:"required"` RunAfterAdd bool `json:"runAfterAdd"` EntryID cron.EntryID `json:"entryID,omitempty"` // contains filtered or unexported fields }
Job
func (*Job) NewJobContext ¶
func (j *Job) NewJobContext() *JobContext
type JobContext ¶
type JobContext struct {
// contains filtered or unexported fields
}
JobContext
func (*JobContext) Error ¶
func (c *JobContext) Error(err error)
func (*JobContext) Name ¶
func (c *JobContext) Name() string
type LoginHandlerResponse ¶
type LoginHandlerResponse struct { Username string Password string Payload jwt.MapClaims Lang string UID uint Error error LocaleMessageID string LocaleMessageDefaultText string LocaleMessageContextValues interface{} }
LoginHandlerResponse
type Menu ¶
type Menu struct { ModelExOrg `rest:"*" displayName:"菜单"` ExtendField Code string `name:"菜单编码" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Dr int64 `name:"删除标记(0表示未删除,非0表示删除时间戳)" gorm:"DEFAULT:0;UNIQUE_INDEX:kuu_unique"` Name string `name:"菜单名称" gorm:"not null"` URI null.String `name:"菜单地址"` Icon null.String `name:"菜单图标"` ParentCode null.String `name:"直接父菜单编号"` ParentCodes null.String `name:"所有父菜单编号"` Group null.String `name:"菜单分组名"` Disable null.Bool `name:"是否禁用"` IsLink null.Bool `name:"是否外链"` Sort null.Int `name:"排序值"` IsDefaultOpen null.Bool `name:"是否默认打开"` Closeable null.Bool `name:"是否可关闭"` LocaleKey null.String `name:"国际化语言键"` IsVirtual null.Bool `name:"是否虚菜单"` AuthPattern null.String `name:"权限表达式"` // json数组 }
Menu
type Message ¶
type Message struct { Model `rest:"*" displayName:"系统消息"` Subject string `name:"消息标题"` Content null.String `name:"消息内容" gorm:"not null"` Attachments []File `name:"消息附件" gorm:"polymorphic:Owner;polymorphic_value:Message.Attachments"` Status int `name:"消息状态" enum:"MessageStatus"` SenderID uint `name:"发送人ID"` SenderUsername string `name:"发送人账号"` Sender *User `name:"发送人" gorm:"foreignkey:SenderID"` SenderSourceIP string `name:"发送人IP地址"` SentAt time.Time `name:"发送时间"` RecipientOrgIDs string `name:"关联接收组织ID(多个以英文逗号分隔)"` RecipientUserIDs string `name:"关联接收人ID(多个以英文逗号分隔)"` RecipientRoleCodes string `name:"关联接收角色编码(多个以英文逗号分隔)"` RecipientReceipts []MessageReceipt `name:"消息接收/阅读回执"` }
func FindUnreadMessages ¶
type MessageReceipt ¶
type MessageReceipt struct { Model `rest:"*" displayName:"消息回执"` MessageID uint `name:"关联消息ID" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Message *Message `name:"关联消息"` RecipientID uint `name:"接收人ID" gorm:"not null;UNIQUE_INDEX:kuu_unique"` RecipientUsername string `name:"接收人账号"` Recipient *User `name:"接收人" gorm:"foreignkey:RecipientID"` RecipientSourceIP string `name:"阅读人IP地址"` ReadAt null.Time `name:"阅读时间"` }
type Metadata ¶
type Metadata struct { ModCode string Name string NativeName string DisplayName string LocaleKey string FullName string Fields []MetadataField RestDesc *RestDesc `json:"-"` SubDocIDNames []string `json:"-" gorm:"-"` UIDNames []string `json:"-" gorm:"-"` OrgIDNames []string `json:"-" gorm:"-"` TagSettings map[string]string `json:"-" gorm:"-"` // contains filtered or unexported fields }
Metadata
func (*Metadata) OmitPassword ¶
func (m *Metadata) OmitPassword(data interface{}) interface{}
OmitPassword
type MetadataField ¶
type MetadataField struct { Code string Name string NativeName string DBType string IsBland bool IsPrimaryKey bool LocaleKey string Kind string Type string Enum string IsRef bool IsPassword bool IsArray bool Value interface{} `json:"-" gorm:"-"` Tag reflect.StructTag `json:"-" gorm:"-"` }
MetadataField
type Mod ¶
type Mod struct { Code string Prefix string Middleware HandlersChain Routes RoutesInfo Models []interface{} IntlMessages map[string]string OnImport func() error OnInit func() error TablePrefix null.String IgnoreCrudRoutes bool IgnoreModRoutes bool IgnoreDataDict bool }
Mod
type Model ¶
type Model struct { ID uint `gorm:"primary_key"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` DeletedAt *time.Time `name:"删除时间,ISO字符串(默认字段)" sql:"index"` OrgID uint `name:"所属组织ID(默认字段)"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` DeletedByID uint `name:"删除人ID(默认字段)"` Remark null.String `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` Org *Org `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:org_id"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` DeletedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:deleted_by_id"` }
Model
type ModelExDel ¶
type ModelExDel struct { ID uint `gorm:"primary_key"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` OrgID uint `name:"所属组织ID(默认字段)"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` Remark null.String `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` Org *Org `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:org_id"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` }
ModelExDel
type ModelExOrg ¶
type ModelExOrg struct { ID uint `gorm:"primary_key"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` DeletedAt *time.Time `name:"删除时间,ISO字符串(默认字段)" sql:"index"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` DeletedByID uint `name:"删除人ID(默认字段)"` Remark null.String `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` DeletedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:deleted_by_id"` }
ModelExOrg
type OperationPrivileges ¶
type OperationPrivileges struct { ModelExOrg `displayName:"角色操作权限"` ExtendField RoleID uint `name:"角色ID"` MenuCode string `name:"菜单编码"` }
OperationPrivileges
type Org ¶
type Org struct { // 引用Model将无法Preload,故复制字段 ID uint `gorm:"primary_key" rest:"*" displayName:"用户"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` DeletedAt *time.Time `name:"删除时间,ISO字符串(默认字段)" sql:"index"` Dr int64 `name:"删除标记(0表示未删除,非0表示删除时间戳)" gorm:"DEFAULT:0;UNIQUE_INDEX:kuu_unique"` OrgID uint `name:"所属组织ID(默认字段)"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` DeletedByID uint `name:"删除人ID(默认字段)"` Remark string `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` Org *Org `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:org_id"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` DeletedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:deleted_by_id"` ExtendField Code string `name:"组织编码" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Name string `name:"组织名称" gorm:"not null"` Pid uint `name:"父组织ID"` Sort int `name:"排序值"` FullPid string FullName string Class string IsBuiltIn null.Bool `name:"是否内置"` }
Org
type Param ¶
type Param struct { gorm.Model `rest:"*" displayName:"参数"` ExtendField Dr int64 `name:"删除标记(0表示未删除,非0表示删除时间戳)" gorm:"DEFAULT:0;UNIQUE_INDEX:kuu_unique"` Code string `name:"参数编码" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Name string `name:"参数名称" gorm:"not null"` Value string `name:"参数值" gorm:"type:text"` Type string `name:"参数类型"` IsBuiltIn null.Bool `name:"是否预置"` }
Param
type PrivilegesDesc ¶
type PrivilegesDesc struct { UID uint OrgID uint Permissions []string PermissionMap map[string]int64 ReadableOrgIDs []uint ReadableOrgIDMap map[uint]Org FullReadableOrgIDs []uint FullReadableOrgIDMap map[uint]Org WritableOrgIDs []uint WritableOrgIDMap map[uint]Org PersonalReadableOrgIDs []uint PersonalReadableOrgIDMap map[uint]Org PersonalWritableOrgIDs []uint PersonalWritableOrgIDMap map[uint]Org LoginableOrgIDs []uint LoginableOrgIDMap map[uint]Org Valid bool SignInfo *SignContext ActOrgID uint ActOrgCode string ActOrgName string RolesCode []string }
PrivilegesDesc
func GetPrivilegesDesc ¶
func GetPrivilegesDesc(signOrContextOrUID interface{}) (desc *PrivilegesDesc)
GetPrivilegesDesc
func GetRoutinePrivilegesDesc ¶
func GetRoutinePrivilegesDesc() *PrivilegesDesc
GetRoutinePrivilegesDesc
func (*PrivilegesDesc) HasPermission ¶
func (desc *PrivilegesDesc) HasPermission(permission string) bool
func (*PrivilegesDesc) HasRole ¶
func (desc *PrivilegesDesc) HasRole(code string) bool
func (*PrivilegesDesc) IsLoginableOrgID ¶
func (desc *PrivilegesDesc) IsLoginableOrgID(orgID uint) bool
IsLoginableOrgID
func (*PrivilegesDesc) IsReadableOrgID ¶
func (desc *PrivilegesDesc) IsReadableOrgID(orgID uint) bool
IsReadableOrgID
func (*PrivilegesDesc) IsWritableOrgID ¶
func (desc *PrivilegesDesc) IsWritableOrgID(orgID uint) bool
IsWritableOrgID
type REContext ¶
type REContext struct { Event RepeatEvent Current int Max int Data map[string]interface{} }
type RepeatEvent ¶
type RepeatEvent struct { Model `rest:"*" displayName:"重试事件"` Name string `name:"任务类型"` EventID string `name:"任务ID"` RetryInterval string `name:"重试间隔"` NextTime *time.Time `name:"下次重试时间"` RetryCount int `name:"重试次数"` Status string `name:"状态" enum:"RepeatEventStatus"` Message string `name:"错误消息" gorm:"type:text"` Data string `name:"上下文数据" gorm:"type:text"` }
type RepeatEventProcesser ¶
type Role ¶
type Role struct { // 引用Model将无法Preload,故复制字段 ID uint `gorm:"primary_key" rest:"*" displayName:"角色"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` DeletedAt *time.Time `name:"删除时间,ISO字符串(默认字段)" sql:"index"` Dr int64 `name:"删除标记(0表示未删除,非0表示删除时间戳)" gorm:"DEFAULT:0;UNIQUE_INDEX:kuu_unique"` OrgID uint `name:"所属组织ID(默认字段)"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` DeletedByID uint `name:"删除人ID(默认字段)"` Remark string `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` Org *Org `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:org_id"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` DeletedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:deleted_by_id"` ExtendField Code string `name:"角色编码" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Name string `name:"角色名称" gorm:"not null"` OperationPrivileges []OperationPrivileges `name:"角色操作权限"` DataPrivileges []DataPrivileges `name:"角色数据权限"` IsBuiltIn null.Bool `name:"是否内置"` }
Role
type RoleAssign ¶
type RoleAssign struct { ModelExOrg `displayName:"用户角色分配"` ExtendField UserID uint `name:"用户ID" gorm:"not null"` RoleID uint `name:"角色ID" gorm:"not null"` Role *Role ExpireUnix int64 }
RoleAssign
type RouteInfo ¶
type RouteInfo struct { Method string Path string Name string HandlerFunc HandlerFunc IgnorePrefix bool Description string Tags []string SignType []string RequestParams route.RequestParams ResponseParams route.ResponseParams IntlMessages map[string]string IntlWithCode bool }
RouteInfo represents a request route's specification which contains method and path and its handler.
type STDReply ¶
type STDReply struct { HTTPAction func(code int, jsonObj interface{}) `json:"-"` HTTPCode int `json:"-"` Code int `json:"code"` Data interface{} `json:"data,omitempty"` Message string `json:"msg,omitempty"` }
func (*STDReply) MarshalJSON ¶
type Scope ¶
type Scope struct { Value interface{} Meta *Metadata ReflectType reflect.Type Context *Context DB *gorm.DB QueryResult *BizQueryResult UpdateCond interface{} UpdateParams *BizUpdateParams // contains filtered or unexported fields }
Scope
type SignContext ¶
type SignContext struct { Token string Type string Lang string UID uint Username string SubDocID uint Payload jwt.MapClaims Secret *SignSecret }
SignContext
type SignHistory ¶
type SignHistory struct { gorm.Model `rest:"*" displayName:"登录历史"` UID uint `name:"用户ID"` SecretID uint `name:"密钥ID"` SecretData string `name:"密钥"` Token string `name:"令牌" gorm:"NOT NULL;INDEX:kuu_token;size:767"` Method string `name:"登录/登出"` }
SignHistory
type SignSecret ¶
type SignSecret struct { gorm.Model `rest:"*" displayName:"令牌密钥"` UID uint `name:"用户ID"` Username string `name:"用户账号"` SubDocID uint `name:"扩展档案ID"` Desc string `name:"令牌描述"` Secret string `name:"令牌密钥"` Payload string `name:"令牌数据(JSON-String)" gorm:"type:text"` Token string `name:"令牌" gorm:"NOT NULL;INDEX:kuu_token;size:767"` Iat int64 `name:"令牌签发时间戳"` Exp int64 `name:"令牌过期时间戳"` Method string `name:"登录/登出"` IsAPIKey null.Bool `name:"是否API Key"` Type string `name:"令牌类型"` }
SignSecret
func GetSignSecret ¶
func GetSignSecret(token string, tx ...*gorm.DB) (*SignSecret, error)
type User ¶
type User struct { // 引用Model将无法Preload,故复制字段 ID uint `gorm:"primary_key" rest:"*" displayName:"用户"` CreatedAt time.Time `name:"创建时间,ISO字符串(默认字段)"` UpdatedAt time.Time `name:"修改时间,ISO字符串(默认字段)"` DeletedAt *time.Time `name:"删除时间,ISO字符串(默认字段)" sql:"index"` Dr int64 `name:"删除标记(0表示未删除,非0表示删除时间戳)" gorm:"DEFAULT:0;UNIQUE_INDEX:kuu_unique"` OrgID uint `name:"所属组织ID(默认字段)"` CreatedByID uint `name:"创建人ID(默认字段)"` UpdatedByID uint `name:"修改人ID(默认字段)"` DeletedByID uint `name:"删除人ID(默认字段)"` Remark string `name:"备注" gorm:"text"` Ts time.Time `name:"时间戳"` Org *Org `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:org_id"` CreatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:created_by_id"` UpdatedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:updated_by_id"` DeletedBy *User `gorm:"association_autoupdate:false;association_autocreate:false;foreignkey:id;association_foreignkey:deleted_by_id"` ExtendField Username string `name:"账号" gorm:"not null;UNIQUE_INDEX:kuu_unique"` Password string `name:"密码" gorm:"not null" json:",omitempty" kuu:"password"` Name string `name:"姓名"` Avatar string `name:"头像"` Sex int `name:"性别"` Mobile string `name:"手机号"` Email string `name:"邮箱地址"` Disable null.Bool `name:"是否禁用"` RoleAssigns []RoleAssign `name:"已分配角色"` IsBuiltIn null.Bool `name:"是否内置"` SubDocIDs string `name:"扩展档案ID映射(令牌类型为键、ID为值的JSON字符串,如{\"ADMIN\":3,\"WECHAT:COMPANY\":2})"` Lang string `name:"最近使用语言"` DenyLogin null.Bool `name:"禁止登录"` ActOrgID uint `name:"当前组织"` LastChangePasswordTime *time.Time `name:"最后修改密码时间"` }
User
func (*User) GetSubDocIDs ¶
GetSubDocIDs
func (*User) SetSubDocID ¶
SetSubDocIDs
type ValidError ¶
ValidError is a validation error struct that hold model, column and error message
func (ValidError) Label ¶
func (err ValidError) Label() string
ValidError is a label including model type, primary key and column name
Source Files ¶
- acc.go
- acc_middlewares.go
- acc_models.go
- acc_routes.go
- aes.go
- audit.go
- biz_callback.go
- biz_callback_create.go
- biz_callback_delete.go
- biz_callback_query.go
- biz_callback_update.go
- biz_scope.go
- cache.go
- cache_bolt.go
- cache_redis.go
- captcha.go
- config.go
- context.go
- create_org.go
- crypto.go
- db.go
- docs.go
- errors.go
- excel.go
- hooks.go
- import.go
- intl.go
- intl_preset.go
- intl_routes.go
- ip.go
- job.go
- kuu.go
- log.go
- log_hooks.go
- message.go
- message_routes.go
- meta.go
- mod.go
- mod_route.go
- model_graphql.go
- model_rest.go
- password.go
- recovery.go
- repeat_event.go
- rsa.go
- sign.go
- sn.go
- stack.go
- sys.go
- sys_auth.go
- sys_callbacks.go
- sys_enum.go
- sys_middlewares.go
- sys_models.go
- sys_routes.go
- token.go
- tools.go
- upload.go
- utils.go
- websocket.go
- websocket_hub.go
- websocket_model.go