Documentation ¶
Index ¶
- Constants
- Variables
- func BizExceptionHandler(biz BizException, ctx iris.Context)
- func BizExceptionViewHandler(biz BizException, ctx iris.Context)
- func CheckPwdStr(input string, store string) bool
- func CheckRst(p *gorm.DB)
- func CloseDbConnection(db *gorm.DB, isBegin *bool)
- func ConsoleError(content string)
- func ConvertToByte(src *string, srcCode string, targetCode string) []byte
- func CutArrayString(arr []string, per int) [][]string
- func CutArrayUint64(arr []uint64, per int) [][]uint64
- func DealFileName(fileName string) string
- func DeleteCache(key string)
- func DeleteHard(db *gorm.DB, table, where string, value ...interface{})
- func DownloadZipFileFromCamp(zipName string, dir []string, files []map[string]string) string
- func EncryptPwdStr(input string) string
- func ExpireCache(key string, lifetime time.Duration) error
- func GetCache(key string, data interface{}) error
- func GetCurrentPath() string
- func GetDbConnectionName(name []string) string
- func GetFileDownloadPath(fileName, filePath string) string
- func GetFilePreviewPath(filePath string) string
- func GetFileSize(filePath string) (int64, bool)
- func GetTotal(db *gorm.DB) int
- func GetUidByTokenInSession(res http.ResponseWriter, req *http.Request) uint64
- func InArrayString(elem string, arr []string) bool
- func InArrayUint64(elem uint64, arr []uint64) bool
- func InArrayUint8(elem uint8, arr []uint8) bool
- func IsEmpty(p interface{}) bool
- func IsExistDir(dirPath string) (bool, error)
- func IsExistFile(filePath string) (bool, error)
- func JsonResponse(j *JsonData, ctx iris.Context)
- func LogError(msg string, data interface{})
- func LogException(msg string)
- func LogInfo(msg string, data interface{})
- func Match(pattern string, str string) bool
- func MkDir(dirPath string) error
- func MkFile(filePath string) error
- func NotFoundHandler(ctx iris.Context)
- func OpenDbConnection(name ...string) *gorm.DB
- func OpenFile(filePath string) *os.File
- func RandomNumber(length int) string
- func RandomStr(length int) string
- func ReadFile(path string) ([]byte, bool)
- func ReadLine(fileName string, handler func(string))
- func Replace(str *string, old string, new string) string
- func Round(f float64) float64
- func SendMail(viewData map[string]string, view, title, to, toName string, e bool) bool
- func SendSms(mobiles []string, code string, templateData map[string]interface{}) bool
- func SetCache(key string, value interface{}, lifetime time.Duration) error
- func SetDefaultRedisClient(client *redis.Client)
- func SetPage(db *gorm.DB, skip int, take int) *gorm.DB
- func SnakeString(s string) string
- func Split(str *string, sep string) []string
- func StartSchedules()
- func StrCut(str string, length int) string
- func StrLL(str *string, subStr string) string
- func StrLR(str *string, subStr string) string
- func StrRL(str *string, subStr string) string
- func StrRR(str *string, subStr string) string
- func Substr(str *string, start int, length ...int) string
- func SysExceptionHandler(ctx iris.Context)
- func SysExceptionViewHandler(ctx iris.Context)
- func ThrowBiz(msg string, code ...int)
- func ThrowSys(msg string, data ...interface{})
- func ToMap(m interface{}, filter []string) map[string]interface{}
- func UniqueArrayString(arr []string) []string
- func UniqueArrayUint64(arr []uint64) []uint64
- func UnixTimeToMdHi(ut int64) string
- func UploadFileMoveToLocal(fileInfo UploadFile) string
- func UploadFileMoveWithFileCamp(fileInfo []UploadFile, token string, ip string) string
- func UploadFilePathForCamp(fileInfo UploadFile, date string) string
- func Uuid() string
- func VerifyCodeCheck(db *gorm.DB, userId uint64, code string, currTime int64)
- func VerifyCodeDeal(db *gorm.DB, userId string)
- func ZipByCommand(fileName string, files string) error
- type Api
- type ApiInterface
- type Base
- func (this *Base) Begin()
- func (this *Base) CloseConnection()
- func (this *Base) Commit()
- func (this *Base) DeleteHard(table, where string, value ...interface{})
- func (this *Base) Error(msg string, code ...int) int
- func (this *Base) GetIp() string
- func (this *Base) GetTotal(obj *gorm.DB) int
- func (this *Base) HasAuth(authKey string) bool
- func (this *Base) Init(data interface{})
- func (this *Base) OpenConnection()
- func (this *Base) QueryPageList(obj *gorm.DB, data interface{})
- func (this *Base) RollBack()
- func (this *Base) SetViewResponse()
- func (this *Base) Success(msg string) int
- func (this *Base) SuccessWithData(data interface{}, msg ...string) int
- func (this *Base) SuccessWithList(list interface{}, total int) int
- func (this *Base) View(viewName string) int
- type BizException
- type JsonData
- type Service
- func (this *Service) AddFormData(key string, value string)
- func (this *Service) AddFormDataForJson(key string, data interface{})
- func (this *Service) Body(code200 ...bool) error
- func (this *Service) ClearParam()
- func (this *Service) Get(code200 ...bool) error
- func (this *Service) LogError(msg string)
- func (this *Service) Post(code200 ...bool) error
- func (this *Service) SetBodyData(bodyData string)
- func (this *Service) SetBodyDataForJson(bodyData interface{})
- func (this *Service) SetCookie(jar *cookiejar.Jar)
- func (this *Service) SetFormData(formData *map[string]string)
- func (this *Service) SetHost(host string)
- func (this *Service) SetPath(path string)
- func (this *Service) SetTls(tls *http.Transport)
- func (this *Service) ToJson(data interface{}) bool
- type Session
- func (s *Session) AddDeviceList(uId string)
- func (s *Session) All() SessionData
- func (s *Session) ClearData()
- func (s *Session) Get(key string) interface{}
- func (s *Session) GetKey() string
- func (s *Session) GetToken() string
- func (s *Session) GetUserAuth() []string
- func (s *Session) GetUserData() map[string]interface{}
- func (s *Session) GetUserRoles() []string
- func (s *Session) IsChanged() bool
- func (s *Session) IsLogged() bool
- func (s *Session) IsNeedLogin() bool
- func (s *Session) RemoveDeviceList(uId string, key string)
- func (s *Session) Set(key string, value interface{})
- func (s *Session) SignIn(uIdField string, user map[string]interface{}, auth, roles []string)
- func (s *Session) SignOut()
- func (s *Session) UpdateSession()
- type SessionData
- type SysException
- type TimerData
- func (t *TimerData) DailyAt(hour int, minute int)
- func (t *TimerData) EveryFiveMinutes()
- func (t *TimerData) EveryMinute()
- func (t *TimerData) EveryTenMinutes()
- func (t *TimerData) EveryThirtyMinutes()
- func (t *TimerData) HourlyAt(minute int)
- func (t *TimerData) MonthlyAt(day int, hour int, minute int)
- func (t *TimerData) SetRepeat(repeat bool) *TimerData
- func (t *TimerData) WeeklyAt(week int, hour int, minute int)
- func (t *TimerData) YearlyAt(month int, day int, hour int, minute int)
- type UploadFile
Constants ¶
View Source
const ( WelCome = `` /* 214-byte string literal not displayed */ ViewErrorMsg = ` <center> <h2>访问出错</h2> <h3>提示:{{.ErrorMsg}}</h3> </center> ` )
View Source
const ( CodeSysError = 1000 CodeSysBusy = 1001 CodeParamError = 2000 CodeBizFailure = 2001 CodeIllegalRequest = 2002 CodeNoLogin = 2003 CodeNoAuth = 2004 CodeToHome = 3000 CodeToResetPwd = 3001 MsgSysError = "抱歉,此功能故障,请联系技术人员" MsgSysBusy = "抱歉,服务器繁忙,请稍后重试" MsgParamError = "参数不符合接口要求,请检查字段类型、嵌套结构的格式等" MsgNoLogin = "请先登录" MsgNoAuth = "抱歉,您的角色没有此功能的操作权限,请联系技术人员" )
Variables ¶
View Source
var (
Exists500File = false
)
Functions ¶
func BizExceptionHandler ¶
func BizExceptionHandler(biz BizException, ctx iris.Context)
func BizExceptionViewHandler ¶
func BizExceptionViewHandler(biz BizException, ctx iris.Context)
func CheckPwdStr ¶
func CloseDbConnection ¶
func CutArrayString ¶
*
- 大数组分割成多个小数组 - 用于批量处理数据的时候,防止SQL参数过大
- @param arr 大数组
- @param per 每个小数组的长度
- @return 小数组
func CutArrayUint64 ¶
*
- 大数组分割成多个小数组 - 用于批量处理数据的时候,防止SQL参数过大
- @param arr 大数组
- @param per 每个小数组的长度
- @return 小数组
func DealFileName ¶
*
- 处理文件名中特殊的字符,将特殊字符转换成下划线
- @param fileName 旧文件名
- @return 转换后的文件名(只是字符串处理,并非正真修改文件名)
func DeleteHard ¶
func DownloadZipFileFromCamp ¶
*
- 从FileCamp服务器上指定的文件夹下打包
- @param filePath 文件路径(相对项目,比如:2019_10_02/uuid.txt)
- @return 预览地址(相对路径,需要前端拼上服务器地址才完整)
func EncryptPwdStr ¶
func GetCache ¶
*
- 获取缓存数据
- @param key 缓存key
- @param data 预期的数据体(结构体、map等类型)
- @return 取值过程发生的错误,或json字符串解析成预期格式出错
func GetDbConnectionName ¶
func GetFileDownloadPath ¶
*
- 获取文件下载路径
- @param fileName 原始文件名称(一般都是中文)
- @param filePath 文件路径(相对项目,比如:2019_10_02/uuid.txt)
- @return 下载地址(相对路径,需要前端拼上服务器地址才完整)
func GetFilePreviewPath ¶
*
- 获取文件预览路径(通过调预览服务器获得)
- @param filePath 文件路径(相对项目,比如:2019_10_02/uuid.txt)
- @return 预览地址(相对路径,需要前端拼上服务器地址才完整)
func GetUidByTokenInSession ¶
func GetUidByTokenInSession(res http.ResponseWriter, req *http.Request) uint64
func IsExistDir ¶
*
- 目录是否存在
- @param dirPath 文件路径
- @return bool 目录是否存在
- @return error 目录存在或不存在时,返回nil;如果目标是非目录或无法读取目标的状态,则返回具体错误信息
func IsExistFile ¶
*
- 文件是否存在
- @param filePath 文件路径
- @return bool 文件是否存在
- @return error 文件存在或不存在时,返回nil;如果目标是目录或无法读取目标的状态,则返回具体错误信息
func JsonResponse ¶
func LogError ¶
func LogError(msg string, data interface{})
*
- 写日志 - Error类
- @param msg 日志标题
- @param data 日志内容(复杂数据类型转换成JSON格式输出)
func LogInfo ¶
func LogInfo(msg string, data interface{})
*
- 写日志 - Info类
- @param msg 日志标题
- @param data 日志内容(复杂数据类型转换成JSON格式输出)
func NotFoundHandler ¶
func OpenDbConnection ¶
func RandomNumber ¶
func SendSms ¶
*
- 发送短信 - 通过msgRouter服务转发
- @param mobiles 手机号数组
- @param code 短信模板名称
- @param templateData 模板参数
func SetCache ¶
*
- 设置缓存数据
- @param key 缓存key
- @param value 数据,将自动转成JSON存储
- @param lifetime 有效时间(秒),0表示永久缓存
- @return 存储缓存过程发生的错误
func SetDefaultRedisClient ¶
func SnakeString ¶
func SysExceptionHandler ¶
func SysExceptionViewHandler ¶
func ThrowSys ¶
func ThrowSys(msg string, data ...interface{})
*
- 抛出系统异常提示,并记录日志
- @param msg 日志的标题
- @param data 非必传,日志内容
func UploadFileMoveToLocal ¶
func UploadFileMoveToLocal(fileInfo UploadFile) string
*
- 上传文件后,将本地临时目录文件迁移至本地正式目录
- @param fileInfo 文件上传回调对象
- @return 正式目录文件路径(可直接用于保存在数据库中)
func UploadFileMoveWithFileCamp ¶
func UploadFileMoveWithFileCamp(fileInfo []UploadFile, token string, ip string) string
*
- 将临时存储的文件迁移到正式目录(支持FTP方式)
- @return fileCamp服务器上目录存储的日期,将【日期值+'/'+uuid.ext】这串保存到数据库中即可
func UploadFilePathForCamp ¶
func UploadFilePathForCamp(fileInfo UploadFile, date string) string
*
- 拼接文件名
- @return 从fileCamp服务器返回的日期+文件uuid和后缀,可将此值直接保存到数据库
func VerifyCodeCheck ¶
func VerifyCodeDeal ¶
Types ¶
type ApiInterface ¶
type ApiInterface interface {
Handler() int
}
type Base ¶
type Base struct { // http对象和常用属性 Ctx iris.Context Method string Path string // 请求时间 Time time.Time TimeStamp int64 // 分页参数 Page int PageSize int Skip int // 默认数据库连接 DB *gorm.DB // 会话数据 Session *Session MyId uint64 MyDeptId uint64 // Json响应 ResData *JsonData IsView bool // contains filtered or unexported fields }
*
- 接口结构体中包含的Base子结构体,提供了各种业务结构需要的数据和方法
func (*Base) DeleteHard ¶
*
- 硬删数据
- 当模型中有DeleteAt字段时,调DB.Delete是软删,而非硬删,因此业务需要硬删时,需要调此方法来物理删除
- 该方法已经校验了SQL执行过程中出现的异常 *
- @param table 表名
- @param where 筛选子句,可以使用占位符
- @param value 筛选子句,代替占位符的值
func (*Base) Error ¶
*
- Json响应 - 业务失败
- @param msg 业务提示信息
- @param code 非必传参数,业务CODE,默认为 CodeBizFailure
- @return 框架响应类型:JSON
func (*Base) Init ¶
func (this *Base) Init(data interface{})
*
- 业务接口初始化Base对象的方法,并处理请求参数
- 规范:在业务接口的New方法中调用,且每次请求只能调用一次,调用格式如下:
- this.Base = this.Init(ctx, this)
func (*Base) QueryPageList ¶
*
- 查询当前分页数据
- @param obj DB对象,在total的DB对象基础上,已经处理了查询列、排序,无需指定分页
- @data interface{} 任意类型的数组或切片结构,外边需要传入指针
func (*Base) SetViewResponse ¶
func (this *Base) SetViewResponse()
*
- 设置本次响应类型为视图,错误处理结果也相应的自动转换成HTML
func (*Base) SuccessWithData ¶
*
- Json响应 - 业务成功,并附带数据体
- @param data 数据体,任意类型的数据(公有属性才可以转成JSON数据)
- @param msg 提示信息,非必传,默认为 "成功"
- @return 框架响应类型:JSON
func (*Base) SuccessWithList ¶
*
- Json响应 - 业务成功,并返回列表数据
- @param list 列表数据,任意类型的数据(列表中的公有属性才可以转成JSON数据)
- @param total 总数
- @return 框架响应类型:JSON
type BizException ¶
type JsonData ¶
type JsonData struct {
// contains filtered or unexported fields
}
func JsonCustom ¶
func JsonSuccess ¶
func JsonSuccessWithData ¶
func JsonSuccessWithList ¶
type Service ¶
type Service struct { ResponseData string StatusCode int // contains filtered or unexported fields }
*
- 发送Http/Https的Server组件 *
- host 主机(协议://IP:端口号)
- path 请求路由
- formData 请求参数
- bodyData 请求body
- ResponseData 响应数据
- StatusCode 响应状态码
- validTls 是否启用tls证书
- tls tls证书
- cookie 会话数据
func (*Service) Body ¶
*
- 发起BodyJson请求
- @param code200 请求码200才算正确请求,其他状态码都一律以错误处理,默认为false
- @return 如果请求发生错误,返回error对象
func (*Service) Get ¶
*
- 发起Get请求
- @param code200 请求码200才算正确请求,其他状态码都一律以错误处理,默认为false
- @return 如果请求发生错误,返回error对象
func (*Service) Post ¶
*
- 发起Post请求
- @param code200 请求码200才算正确请求,其他状态码都一律以错误处理,默认为false
- @return 如果请求发生错误,返回error对象
func (*Service) SetBodyDataForJson ¶
func (this *Service) SetBodyDataForJson(bodyData interface{})
*
- 设置请求参数,自动转成JSON格式(bodyData)
- @param bodyData 请求参数
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
*
- 某个请求生命周期内,业务逻辑的会话数据结构
func (*Session) AddDeviceList ¶
func (*Session) All ¶
func (s *Session) All() SessionData
func (*Session) GetUserAuth ¶
func (*Session) GetUserData ¶
func (*Session) GetUserRoles ¶
func (*Session) IsNeedLogin ¶
func (*Session) RemoveDeviceList ¶
func (*Session) SignIn ¶
*
- 注册会话
- @param uIdField 用户ID字段名,一般都是"UserId"
- @param user 用户信息map结构
- @param auth 权限key的集合
- @param roles 角色Id的集合
func (*Session) UpdateSession ¶
func (s *Session) UpdateSession()
type SessionData ¶
type SessionData struct { // 是否已经登录 Flag bool // 用户信息 User map[string]interface{} // 拥有的权限key的集合 Auth []string // 所属角色id的集合 Roles []string }
*
- 存储在redis中的某个用户的会话数据结构
type SysException ¶
type TimerData ¶
type TimerData struct {
// contains filtered or unexported fields
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.