reqresp

package
v0.0.0-...-849f898 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyClientIP       = "ctx.client.ip"
	CtxKeyUuid           = "ctx.client.uuid"
	CtxKeyAppID          = "ctx.client.appid"
	CtxKeyVersion        = "ctx.client.version"
	CtxKeyDeviceID       = "ctx.client.deviceid"
	CtxKeyRequestID      = "ctx.client.rid"
	CtxKeyRequestTime    = "ctx.client.rtimestamp"
	CtxKeyEchoToken      = "ctx.client.echo_token"
	CtxKeyMetricName     = "ctx.g.metric_name"
	CtxKeyRequestData    = "ctx.request.data"
	CtxKeyResponseData   = "ctx.response.data"
	CtxKeyResponseObject = "ctx.response.object"
	CtxKeySessionToken   = "ctx.session.token"
)

Variables

This section is empty.

Functions

func CtxGetRaw

func CtxGetRaw(c context.Context, key string) []byte

CtxGetRaw ...

func CtxGetStr

func CtxGetStr(c context.Context, key string) string

CtxGetStr ...

func CtxSetRaw

func CtxSetRaw(c *gin.Context, key string, data []byte)

CtxSetRaw ...

func F

func F(ctx context.Context, format string, args ...interface{}) string

F 打印出带上下文的日志

func MakeCtx

func MakeCtx(c *gin.Context) context.Context

MakeCtx 返回标准格式的 context

func RequestUnmarshal

func RequestUnmarshal(c *gin.Context, data IRequest) (context.Context, error)

RequestUnmarshal 解析入参

func ResponseMarshal

func ResponseMarshal(c *gin.Context, err error, data IResponse)

ResponseMarshal 序列化应答数据 s.BaseError

Types

type IRequest

type IRequest interface {
	GetCommon() *ReqCommonData
}

IRequest the interface of request datas

type IResponse

type IResponse interface {
	GetCommon() *RespCommonData
}

IResponse the interface of response datas

type ReqCommon

type ReqCommon struct {
	Common ReqCommonData `json:"common"`
}

ReqCommon common header in a request

func (*ReqCommon) GetCommon

func (r *ReqCommon) GetCommon() *ReqCommonData

type ReqCommonData

type ReqCommonData struct {
	Uid       string `json:"uid,omitempty"`
	AppID     string `json:"appid,omitempty"`
	SessToken string `json:"session_token"`
	RequestID string `json:"request_id,omitempty"`
	DeviceID  string `json:"device_id,omitempty"`
	Timestamp int64  `json:"timestamp"`
	EchoToken string `json:"echo_token"`
}

type RespCommon

type RespCommon struct {
	Common RespCommonData `json:"common"`
}

RespCommon common header in a response

func (*RespCommon) GetCommon

func (r *RespCommon) GetCommon() *RespCommonData

type RespCommonData

type RespCommonData struct {
	Ret       int    `json:"ret"`
	Msg       string `json:"msg"`
	RequestID string `json:"request_id,omitempty"`
	Timestamp int64  `json:"timestamp"`
	RetryMS   int32  `json:"retry_ms"`
	EchoToken string `json:"echo_token"`
}

Jump to

Keyboard shortcuts

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