api

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Zlib Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	KHead  = "HEADER"
	KToken = "TOKEN"
	KUid   = "UID"
)
View Source
const (
	UNK   = "unk"
	XML   = "xml"
	JSON  = "json"
	PLAIN = "plain"

	MimeJSON              = "application/json"
	MimeHTML              = "text/html"
	MimeXML               = "application/xml"
	MimeXML2              = "text/xml"
	MimePlain             = "text/plain"
	MimePOSTForm          = "application/x-www-form-urlencoded"
	MimeMultipartPOSTForm = "multipart/form-data"
	MimePROTOBUF          = "application/x-protobuf"
	MimeMSGPACK           = "application/x-msgpack"
	MimeMSGPACK2          = "application/msgpack"
	MimeYAML              = "application/x-yaml"
)
View Source
const (
	CSysVersion = "X-H79-SysVersion"
	CDeviceId   = "X-H79-DeviceId"
	CModel      = "X-H79-Model"
	CWifi       = "X-H79-Wifi"
	CChannel    = "X-H79-Channel"
	CExtInfo    = "X-H79-ExtInfo"
	CTerminal   = "terminal"
	CAppId      = "appId"
	CVersion    = "version"
	CSeqId      = "seqId"
	CSource     = "source"
	CTimeAt     = "timeAt"
	CToken      = "Authorization"
)

Variables

View Source
var DefErrorHttpCode = http.StatusOK

Functions

func Bearer added in v0.5.8

func Bearer(tok string) string

func BindClientAuth

func BindClientAuth(ctx Context, source token.Source) error

func BindHead added in v0.5.22

func BindHead(ctx Context, option HeadOption)

func BindServerAuth

func BindServerAuth(ctx Context, source token.Source) error

func ContentTypeTo added in v0.1.2

func ContentTypeTo(ct string) string

func Get added in v0.1.2

func Get[T any](ctx Context, key string) T

func GetApp added in v0.5.19

func GetApp(ctx Context) app.Info

func GetClientIP

func GetClientIP(ctx Context) string

func GetContentType

func GetContentType(ctx Context) string

func GetCustom added in v0.5.19

func GetCustom(ctx Context) interface{}

func GetSystem added in v0.5.19

func GetSystem(ctx Context) app.System

func GetTokenSource added in v0.5.18

func GetTokenSource(ctx Context) token.Source

func GetUid

func GetUid(ctx Context) string

func GetUidI64 added in v1.0.58

func GetUidI64(ctx Context) int64

func HeadInt64

func HeadInt64(ctx Context, key string) int64

func ParamInt64

func ParamInt64(ctx Context, key string) int64

func QueryInt64

func QueryInt64(ctx Context, key string) int64

func Send

func Send(ctx Context, result result.Result, data interface{})

func SendException

func SendException(ctx Context, req request.HeadV2)

func SendStatusNoHead added in v0.5.19

func SendStatusNoHead(ctx Context, httpCode int, result result.Result, data interface{})

func SendWithHead added in v0.5.25

func SendWithHead(ctx Context, req request.HeadV2, result result.Result, data interface{})

func SendWithStatus added in v0.4.6

func SendWithStatus(ctx Context, httpCode int, req request.HeadV2, result result.Result, data interface{})

func SetUid added in v0.1.2

func SetUid(ctx Context, uid string)

func SetUidI64 added in v1.0.58

func SetUidI64(ctx Context, uid int64)

func WithHeadOption added in v1.0.1

func WithHeadOption(ctx Context, header *Header)

Types

type Base

type Base struct {
	ClientIP string
	System   app.System
	App      app.Info
}

func GetBase

func GetBase(ctx Context) Base

type CacheContext added in v0.1.4

type CacheContext interface {
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
}

type Context added in v0.1.2

type Context interface {
	HttpContext() HttpContext
	HeaderContext() HeaderContext
	CacheContext() CacheContext
	AuthContext() token.Engine
}

type HeadOption added in v1.0.1

type HeadOption func(ctx Context, header *Header)
type Header struct {
	Base
	ReqHead
	Token string
	// 自定义属性
	Custom interface{}
}

func GetHead added in v0.5.19

func GetHead(ctx Context) *Header

func NewHeader

func NewHeader(req ReqHead) *Header

func (*Header) HasApp added in v1.0.1

func (h *Header) HasApp() bool

func (*Header) HasDeviceId

func (h *Header) HasDeviceId() bool

func (*Header) HasSystem added in v1.0.1

func (h *Header) HasSystem() bool

func (*Header) HasToken

func (h *Header) HasToken() bool

func (*Header) ReadFrom added in v0.1.4

func (h *Header) ReadFrom(ctx Context)

func (*Header) WriteTo added in v0.1.4

func (h *Header) WriteTo(ctx Context)

type HeaderContext added in v0.1.4

type HeaderContext interface {
	Set(key, value string)
	Get(key string) string
}

type HttpContext added in v0.1.4

type HttpContext interface {
	Send(httpCode int, data Response)
	Abort()
	Next()
	Param(key string) string
	Query(key string) string
	ClientIP() string
}

type ReqHead

type ReqHead struct {
	Version string        `form:"version" binding:"-" json:"version"`
	Source  string        `form:"source" binding:"-" json:"source"`
	SeqId   string        `form:"seqId" binding:"-" json:"seqId"`
	ReqAt   int64         `form:"timeAt" binding:"-" json:"timeAt"` //请求者的时间(客户端时间)
	RecvAt  int64         `json:"-"`                                //收到请求时间(服务端时间)
	TimeOut time.Duration `json:"-"`
}

func GetReqHead

func GetReqHead(ctx Context) ReqHead

func (*ReqHead) GetRecvAt added in v0.6.7

func (h *ReqHead) GetRecvAt() int64

GetRecvAt request.HeadV2 interface

func (*ReqHead) GetReqAt added in v0.6.7

func (h *ReqHead) GetReqAt() int64

GetReqAt request.HeadV2 interface

func (*ReqHead) GetSeqId

func (h *ReqHead) GetSeqId() string

GetSeqId request.Head interface

func (*ReqHead) GetSource

func (h *ReqHead) GetSource() string

GetSource request.Head interface

func (*ReqHead) GetTimeOut

func (h *ReqHead) GetTimeOut() time.Duration

GetTimeOut request.HeadV2 interface

func (*ReqHead) GetVersion

func (h *ReqHead) GetVersion() string

GetVersion request.Head interface

func (*ReqHead) SetSource

func (h *ReqHead) SetSource(source string)

SetSource request.HeadV2 interface

func (*ReqHead) SetTimeOut

func (h *ReqHead) SetTimeOut(duration time.Duration)

SetTimeOut request.HeadV2 interface

type Request

type Request struct {
	ReqHead
	Data string `json:"data,omitempty"` //json format string
}

func NewRequest

func NewRequest() Request

type ResHead

type ResHead struct {
	result.Result
	Version  string `json:"version"`            //版本,请求者版本
	Source   string `json:"source,omitempty"`   //请求源,可以请求者填写
	SeqId    string `json:"seqId,omitempty"`    //请求序号,由请求者定义,服务器原路返回
	TimeAt   int64  `json:"timeAt,omitempty"`   //服务收到请求的时间(ms)
	DiffAt   int64  `json:"diffAt,omitempty"`   //客户端与服务端时间差值(ms)
	SpendAt  int64  `json:"spendAt,omitempty"`  //从服务收到请求到响应完成,所花的时长(ms)
	ServerAt int64  `json:"serverAt,omitempty"` //服务器时间,豪秒,用于检验对时(ms)
	LogId    string `json:"logId,omitempty"`
}

func NewResHead

func NewResHead(res result.Result) ResHead

type Response

type Response struct {
	ResHead
	EventType int32       `json:"eventType,omitempty"` //回应事件类型(业务自己定义,比如tcp,websocket)
	Data      interface{} `json:"data,omitempty"`      //业务具体数据
}

func NewResponse

func NewResponse(head request.HeadV2, result result.Result, data interface{}) Response

func NewResponseWithError added in v0.5.19

func NewResponseWithError(head request.HeadV2, err error, data interface{}) Response

Jump to

Keyboard shortcuts

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