protocolstack

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GinKeyReqBody       = "_ReqBody"       // 请求body数据
	GinKeyRspBase       = "_RspStructBase" // RspStructBase
	GinKeyBodyInterface = "_BodyInterface" // 请求参数中的 Interface
)

Variables

This section is empty.

Functions

func CommJsonResponse

func CommJsonResponse(ctx *gin.Context, err errcode.AppError, data interface{}, errInfo ...string)

通用协议:接口响应数据结构封装

func GetReqBodyToStruct

func GetReqBodyToStruct(body []byte, appParams interface{}) (interface{}, error)

通过body,格式化请求参数

func MiddlewareRsp

func MiddlewareRsp(ctx *gin.Context, httpCode int, err errcode.AppError)

func NewReqBody

func NewReqBody() interface{}

New Req Body

func NewRspBody

func NewRspBody() interface{}

New Rsp Body

func RegisterProDealFunc

func RegisterProDealFunc(funcs ...FuncCtx)

注册协议处理函数

func RegisterProtocol

func RegisterProtocol(protocolFunc func() ProtocolBase)

注册协议的请求参数格式 和 返回参数格式

Types

type FuncCtx

type FuncCtx func(body []byte, header http.Header) errcode.AppError

用于gin中间件调用

func GetDealFuncs

func GetDealFuncs() []FuncCtx

获取处理函数

type ProtocolBase

type ProtocolBase interface {
	NewReqBody() interface{} // New Req Body
	NewRspBody() interface{} // New Rsp Body

	// 通过body,格式化请求参数
	GetReqBodyToStruct(body []byte, appParams interface{}) (interface{}, error)
	// 通过请求body,获取相应接口信息
	GetRspByResBody(body []byte) (RspStructBase, error)
	// 通过请求body,获取请求结构体和相应接口信息
	GetReqAndRspByResBody(body []byte, appParams interface{}) (RspStructBase, interface{}, error)
}

协议类接口

type RspStructBase

type RspStructBase interface {
	SetRspError(err errcode.AppError, strErr ...string)
	SetData(data interface{})
	ToString() string

	// 请求&响应的Interface是一致的,所以可以通过响应体获取Interface
	GetBodyInterface() string
}

response struct 相关的类接口

func GetReqAndRspByResBody

func GetReqAndRspByResBody(body []byte, appParams interface{}) (RspStructBase, interface{}, error)

通过请求body,获取请求结构体和相应接口信息

func GetRspByResBody

func GetRspByResBody(body []byte) (RspStructBase, error)

通过请求body,获取相应接口信息

Jump to

Keyboard shortcuts

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