api

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 成功
	Success ErrorNo = 0
	// 请求
	ReqPathError          = 10001
	ReqVersionNoExist     = 10002
	ReqInterfaceNoExist   = 10003
	ReqCommandNoExist     = 10004
	ReqInterfaceNoSupport = 10005
	ReqNoAllow            = 10006
	ReqTokenError         = 10007

	// 公共
	CommonPageError         = 20001 // 分页错误
	CommonParamError        = 20002 // 参数错误
	CommonParamConvertError = 20003 // 参数转换错误
	CommonSignError         = 20004 // 签名错误
	CommonAppError          = 20008 // app错误

	// 业务参数
	BusParamError        = 30001 // 参数错误
	BusParamConvertError = 30002 // 参数转换错误

	// 服务端处理异常
	ServiceError = 50001
)

Variables

View Source
var ReturnMsg = map[ErrorNo]string{

	Success: "success",

	ReqPathError:          "请求路径错误",
	ReqVersionNoExist:     "请求版本不存在",
	ReqInterfaceNoExist:   "请求接口不存在",
	ReqCommandNoExist:     "请求命令不存在",
	ReqInterfaceNoSupport: "接口在当前请求命令中未被支持",
	ReqNoAllow:            "请求不允许",
	ReqTokenError:         "Token不正确,请重新获取",

	CommonPageError:         "分页错误",
	CommonParamError:        "公共参数错误",
	CommonParamConvertError: "公共参数转换错误",
	CommonSignError:         "公共参数签名错误",
	CommonAppError:          "商户账户不存在或不可用",

	BusParamError:        "业务参数错误",
	BusParamConvertError: "业务参数转换错误",

	ServiceError: "服务端处理异常",
}

Functions

func HandleError

func HandleError(c echo.Context, errcode ErrorNo, errmsg ...string) error

* 错误返回

func HandleSuccess

func HandleSuccess(c echo.Context, i ...interface{}) error

* 正常返回

func HandleSuccessReq

func HandleSuccessReq(ctx context.Context, c echo.Context, r *ReqParam, v interface{}) error

func JWT

func JWT(next echo.HandlerFunc) echo.HandlerFunc

验证jwt

func MetricsFunc

func MetricsFunc(m *metrics2.Metrics) echo.MiddlewareFunc

metrics

func NoSign

func NoSign(next echo.HandlerFunc) echo.HandlerFunc

verifyparam// trace

func RPCErr

func RPCErr(c echo.Context, err error) error

RPC错误处理

func TraceHeader

func TraceHeader(next echo.HandlerFunc) echo.HandlerFunc

func VerifyParam

func VerifyParam(next echo.HandlerFunc) echo.HandlerFunc

Types

type ErrorNo

type ErrorNo int64

func (ErrorNo) String

func (e ErrorNo) String() string

type ReqParam

type ReqParam struct {
	AppID     int        `json:"-"`                                                    // AppID
	AppKey    string     `json:"app_key" valid:"required~appKey必须存在"`                  // 密钥ID
	AppSecret string     `json:"app_secret" valid:"-"`                                 // 密钥
	RequestID string     `json:"request_id" valid:"required~required必须存在"`             // 32位的唯一请求标识,用于问题排查和防止重复提交
	Timestamp string     `json:"timestamp" valid:"required~毫秒时间戳必须存在"`                 // 毫秒时间戳
	Custom    string     `json:"custom" valid:"-"`                                     // 第三方自定义内容
	Nonce     string     `json:"nonce" valid:"required~随机数必须存在,length(8|8)~随机数必须满足8位"` // 8 位随机数
	Language  string     `json:"language" valid:"in(cn|en)"`                           // 多语言支持
	Sign      string     `json:"sign" valid:"required~签名必须存在"`                         // 签名
	SignType  string     `json:"sign_type" valid:"required~签名类型必须存在"`                  // 签名类型:MD5 SHA_1 SHA_256 SHA_512
	Encode    bool       `json:"encode" valid:"-"`                                     // 响应数据data是否进行base64编码,默认true
	Data      string     `json:"data" valid:"-"`                                       // 请求的数据
	Remark    string     `json:"remark"`
	Code      string     `json:"code"`
	Message   string     `json:"message"`
	Page      utils.Page `json:"page"`    // 分页
	IsPage    bool       `json:"is_page"` // 是否分页
}

func (*ReqParam) CompareSign

func (r *ReqParam) CompareSign() (bool, error)

* 根据签名类型比较签名 true:相同 false:不同

func (*ReqParam) CreateSign

func (r *ReqParam) CreateSign() (string, error)

生成签名 string

func (*ReqParam) DataDecode

func (r *ReqParam) DataDecode(v interface{}) error

* **解析data参数 **input: v point **output: error

func (*ReqParam) DataEncode

func (r *ReqParam) DataEncode(v interface{}) error

* **编码data参数 **input: v interface **output: error

func (*ReqParam) Decode

func (r *ReqParam) Decode(s string) error

func (*ReqParam) R

func (r *ReqParam) R(v interface{}) (interface{}, error)

返回数据

0.生成data数据和page数据 1.encode data数据 2.生成时间错和签名 3.生成错误吗和错误信息 4.返回数据

func (*ReqParam) Validate

func (r *ReqParam) Validate() error

func (*ReqParam) ValidateAppSecret

func (r *ReqParam) ValidateAppSecret() error

Jump to

Keyboard shortcuts

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