common

package
v0.0.0-...-7a729f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 14 Imported by: 7

Documentation

Index

Constants

View Source
const (
	ENCRYPT_TYPE                   = "EncryptType"       // 加密类型KEY
	ENCRYPT_TYPE_AES_PRIV_REQ      = "AES_PRIV_REQ"      // 请求加密
	ENCRYPT_TYPE_AES_PRIV_RESP     = "AES_PRIV_RESP"     // 响应加密
	ENCRYPT_TYPE_AES_PRIV_REQ_RESP = "AES_PRIV_REQ_RESP" // 请求和响应都加密
	ERR_CODE_ENCRYPT_FAILED        = 9001                // 加密响应body失败
)
View Source
const (
	MultiSelect      = "multi-select"       // 多选
	MultiText        = "multi-text"         // 模糊多选
	NumRange         = "num-range"          // 数字范围或者数字查询
	NotIn            = "not-in"             // 不在范围内
	Range            = "range"              // 日期区间的查询
	CommaMultiSelect = "comma-multi-select" //数据库中存放是逗号分隔的值
)

查询条件常量

View Source
const (
	TokenKey           = "Authorization"
	UserNameSessionKey = "X-UserName"
	CodeKey            = "X-Code"
	AppTag             = "APPID"
)

Variables

View Source
var (
	//NotFound not found
	NotFound = customerror.New(404, "NOT_FOUND")
	//ErrServer 服务器错误
	ErrServer = customerror.New(500, "服务器错误")
	//SignError sign error
	SignError = customerror.New(1103, "Sign签名错误")

	//ParamsError json error
	ParamsError = customerror.New(1101, "参数格式错误")
	// Validate error
	ParamsValidateError = customerror.New(1102, "参数校验错误")
	//InternalServerError 500
	InternalServerError = customerror.New(500, "INTERNAL_SERVER_ERROR")

	//ParamsFormatError 参数格式错误
	ParamsFormatError = customerror.New(1102, "PARAMS_FORMAT_ERROR")

	//LoginTokenInvalid  登录token失效
	LoginTokenInvalid = customerror.New(1104, "LOGIN_TOKEN_INVALID")

	//AppIDError AppIDError
	AppIDError = customerror.New(1105, "AppID Error")
	//TimestampError TimestampError
	TimestampError = customerror.New(1106, "Timestamp Error")

	//AccountError 账号或密码错误
	AccountError = customerror.New(2102, "ACCOUNT_ERROR")

	// TOKEN 不存在
	TokenNotFound = customerror.New(3000, "Token信息不存在")

	//AccessTokenExpire 帐号app的token过期
	AccessTokenExpire = customerror.New(3001, "AccessToken Error or Expire")
	//RefreshTokenExpire 帐号app的刷新令牌过期
	RefreshTokenExpire = customerror.New(3002, "RefreshToken Error or Expire")
	TokenInvalid       = customerror.New(3003, "非法的token")
	// 用户认证信息不存在
	UnameNotFound = customerror.New(3005, "用户认证信息不存在")
	//OauthCodeExpire accesstoken过期
	OauthCodeExpire = customerror.New(3006, "Oauth Code Expire")
	//
	AuthStateInvalid = customerror.New(3007, "Auth state 不正确")
	//
	AuthCodeInvalid = customerror.New(3008, "Auth code 不正确")
	//
	UserNameOrPasswordInvalid = customerror.New(5009, "用户名或者密码错误")
	// LdapErr 域账号登陆异常
	LdapErr = customerror.New(5005, "域账号登陆异常")
	// DisabledUser 禁用的用户
	DisabledUser       = customerror.New(5006, "禁用的用户")
	AnotherClientLogin = customerror.New(50008, "其他客户端登录了")
	//GetCodeFrequently 请求验证码次数过多
	GetCodeFrequently = customerror.New(3009, "请求验证码次数过多")
	//VerificationCodeeError 验证码错误
	VerificationCodeeError = customerror.New(3010, "验证码错误")

	//ImageError 图片格式不支持
	ImageError = customerror.New(4001, "该图片格式不支持")
	//NicknameError 昵称错误
	NicknameError = customerror.New(4002, "昵称包含禁用词")
	// UserAlreadyExist 创建的用户已经存在
	UserAlreadyExist = customerror.New(5001, "用户已存在")
	// UserDoesNotExist 用户不存在
	UserDoesNotExist = customerror.New(5002, "用户不存在")
	// WrongPassword 密码错误
	WrongPassword = customerror.New(5003, "密码错误")
)
View Source
var (
	ServerErr            = customerror.New(500, "服务器错误")
	QueryCondErr         = customerror.New(1001, "查询条件不正确")
	StepTypeNotFound     = customerror.New(1002, "Flow Step 不存在")
	ServiceIdNotInt      = customerror.New(1003, "Service Id格式不正确")
	ParamsErr            = customerror.New(1004, "参数错误")
	UploadErr            = customerror.New(1005, "上传文件失败")
	UpdateActionNotFound = customerror.New(1006, "Update Acton 不存在")
	ActionNotFound       = customerror.New(1007, "Action 不存在")
)

Functions

func BSAuth

func BSAuth(ctx *context.Context)

通过黑鲨账号认证

func GetLogsPath

func GetLogsPath() (path string)

GetLogsPath

func GetPath

func GetPath(l []string) (path string)

GetPath 获取相对当前路径的通用路径

func GetRootPath

func GetRootPath() (rootpath string)

func GetTplPath

func GetTplPath() (path string)

GetTplPath

func GetUploadPath

func GetUploadPath() (path string)

GetUploadPath ...

func TokenDealFilter

func TokenDealFilter(ctx *context.Context)

解析token,存储username

Types

type BaseController

type BaseController struct {
	REST             StandRestResultInf
	beego.Controller // beego 基础控制器
}

BaseController ... 所有控制controller的基础struct

func (*BaseController) GetStandRestResult

func (b *BaseController) GetStandRestResult() StandRestResultInf

func (*BaseController) JSONResponse

func (c *BaseController) JSONResponse(err error, data ...interface{})

JSONResponse 返回JSON格式结果

func (*BaseController) SaveToFileCustomName

func (c *BaseController) SaveToFileCustomName(fromfile string, fc func(*multipart.FileHeader) string) error

SaveToFileCustomName saves uploaded file to new path with custom name. it only operates the first one of mutil-upload form file field.

func (*BaseController) ServeDecryptJSON

func (c *BaseController) ServeDecryptJSON()

ServeSelfJSON ... Controller 自定义方法,用来处理加密返回

func (*BaseController) ValidateParameters

func (c *BaseController) ValidateParameters(obj interface{}) customerror.CustomError

ValidateParameters obj must pointer, json Unmarshal object and require parameter validate

type QueryConditon

type QueryConditon struct {
	QueryKey    string
	QueryType   string // multi-select  multi-text  num-range  comma-multi-select
	QueryValues []string
}

QueryConditon 表格查询条件对象

func QueryKeyReplace

func QueryKeyReplace(query []*QueryConditon, repMap map[string]string) (ret []*QueryConditon)

type RestResult

type RestResult struct {
	Code    int         // 0 表示成功,其他失败
	Message string      // 错误信息
	Data    interface{} // 数据体
}

RestResult Rest接口返回值(兼容特性使用)

type StandRestResult

type StandRestResult struct {
	Code    int         `json:"code"`    // 0 表示成功,其他失败
	Message string      `json:"message"` // 错误信息
	Data    interface{} `json:"data"`    // 数据体
}

标准的 rest 返回接口,字符小写化

func (StandRestResult) GetStandRestResult

func (rest StandRestResult) GetStandRestResult(code int, msg string, data interface{}) interface{}

type StandRestResultInf

type StandRestResultInf interface {
	GetStandRestResult(code int, msg string, data interface{}) interface{}
}

返回接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL