common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonResponse

func CommonResponse(c *gin.Context, code RespCode, httpCode int, data interface{}, err error)

通用响应封装

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 IsValidPasswd

func IsValidPasswd(passStr, salt, passHash string) bool

校验密码

func ResponseClientError

func ResponseClientError(c *gin.Context, err error)

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

func ResponseInvalidParam

func ResponseInvalidParam(c *gin.Context, err error)

参数校验错误响应体封装

func ResponseMethodNotAllowed

func ResponseMethodNotAllowed(c *gin.Context, err error)

func ResponseOk

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

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

func ResponseServerError

func ResponseServerError(c *gin.Context, err error)

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

func ResponseUnAuthorized

func ResponseUnAuthorized(c *gin.Context, err error)

未鉴权访问

Types

type RespCode

type RespCode int
const (
	ResponseCodeOk RespCode = iota
	ResponseCodeClientError
	ResponseCodeServerError

	ResponseCodeInvalidParam
	ResponseCodeUnAuthorized
	ResponseCodeMethodNotAllowed
)

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

func (RespCode) String

func (code RespCode) String() string

type RespStruct

type RespStruct struct {
	Code  RespCode    `json:"code"`
	Msg   string      `json:"code_msg"`
	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