common

package
v0.0.0-...-3208bda Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelString

func CamelString(s string) string

camel string, xx_yy to XxYy

func CompareStringSlice

func CompareStringSlice(a, b []string) bool

判断量字符串切片是否相等 如其他类型可用:reflect.DeepEqual(a, b)

func EF

func EF(err error)

退出程序的错误处理,一般用于初始化失败时的错误输出,此时程序正在启动时发生错误,std打印即可。

func GenHash

func GenHash(src string) string

生成随机40位哈希

func GenPassHash

func GenPassHash(src string) (hashStr, salt string)

用户密码加盐生成哈希

func GenTraceId

func GenTraceId(ip string) (traceId string)

func GetLocalIPs

func GetLocalIPs() (ips []net.IP)

func IsExsitItem

func IsExsitItem(v interface{}, s interface{}) bool

判断切片是否存在元素

func IsValidPasswd

func IsValidPasswd(passStr, salt, passHash string) bool

校验密码

func MapToStruct

func MapToStruct(mapData map[string]interface{}, structData interface{}) error

func Response

func Response(c *gin.Context, code RespCode, httpCode int, data interface{}, errorString string)

通用响应封装

func ResponseAuthMiddlerwareError

func ResponseAuthMiddlerwareError(c *gin.Context, errorContent string)

auth middleware error response

func ResponseCacheError

func ResponseCacheError(c *gin.Context, errorContent string)

cache error response

func ResponseCasbinApiError

func ResponseCasbinApiError(c *gin.Context, errorContent string)

casbin api error response

func ResponseClientError

func ResponseClientError(c *gin.Context, errorContent string)

客户端错误响应的封装 (http 400)

func ResponseCorsMiddlewareError

func ResponseCorsMiddlewareError(c *gin.Context, errorContent string)

cors middleware error response

func ResponseEmptyResult

func ResponseEmptyResult(c *gin.Context, errorContent string)

返回空结果或查询不到结果

func ResponseHandlerError

func ResponseHandlerError(c *gin.Context, errorContent string)

handler error response

func ResponseInvalidParam

func ResponseInvalidParam(c *gin.Context, errorContent string)

参数校验错误响应体封装

func ResponseMethodNotAllowed

func ResponseMethodNotAllowed(c *gin.Context, errorContent string)

访问方法不被允许

func ResponseModelError

func ResponseModelError(c *gin.Context, errorContent string)

model error response

func ResponseOk

func ResponseOk(c *gin.Context, data interface{})

请求成功响应的封装 (http 200)

func ResponseRbacMiddlewareError

func ResponseRbacMiddlewareError(c *gin.Context, errorContent string)

rbac middleware error response

func ResponseRepositoryError

func ResponseRepositoryError(c *gin.Context, errorContent string)

repository error response

func ResponseServerError

func ResponseServerError(c *gin.Context, errorContent string)

服务端错误响应的封装 (http 500)

func ResponseUnAuthorized

func ResponseUnAuthorized(c *gin.Context, errorContent string)

未鉴权访问

func SnakeString

func SnakeString(s string) string

snake string, XxYy to xx_yy , XxYY to xx_yy

func StructToMap

func StructToMap(structData interface{}) map[string]interface{}

func Unzip

func Unzip(zipFile string, destDir string) error

func Zip

func Zip(srcFile string, destZip string) error

srcFile could be a single file or a directory

Types

type RespCode

type RespCode int
const (
	ResponseCodeOk RespCode = iota
	ResponseCodeClientError
	ResponseCodeServerError

	ResponseCodeInvalidParam
	ResponseCodeUnAuthorized
	ResponseCodeMethodNotAllowed
	ResponseCodeEmptyResult

	ResponseCodeHandlerError
	ResponseCodeModelError
	ResponseCodeRepositoryError
	ResponseCodeCacheError
	ResponseCodeCasbinError
	ResponseCodeAuthMiddlerwareError
	ResponseCodeCorsMiddlerwareError
	ResponseCodeRbacMiddlerwareError
)

定义用户级别的返回码,并枚举其信息输出

func (RespCode) String

func (code RespCode) String() string

type RespStruct

type RespStruct struct {
	Code  RespCode    `json:"code"`
	Msg   string      `json:"message"`
	Error string      `json:"error"`
	Data  interface{} `json:"data"`
}

统一返回消息体

Jump to

Keyboard shortcuts

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