api

package
v1.20.57 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Zlib Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Head  = "HEADER"
	Token = "TOKEN"
	Uid   = "UID"
)
View Source
const (
	UNK         = "unk"
	XML         = "xml"
	JSON        = "json"
	PLAIN       = "plain"
	ContentType = "Content-Type"
)
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"
	CSign       = "sign"
	CTimeStamp  = "timestamp"
	XReqTime    = "X-ReqTime"
	XSeqId      = "X-SeqNo"
	XSign       = "X-Sign"
	XTimeStamp  = "X-Timestamp"
)
View Source
const (
	TypePage = iota + 1000
	TypeEventType
)

Variables

View Source
var DefErrorHttpCode = http.StatusOK

Functions

func Bearer added in v0.5.8

func Bearer(tok string) string

func BindHead added in v0.5.22

func BindHead(ctx Context, option HeadOption)

func ContentTypeTo added in v0.1.2

func ContentTypeTo(ct string) string

func EventTypeExist added in v1.8.38

func EventTypeExist(opts ...option.Option) (int32, bool)

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 GetInt64Uid added in v1.0.36

func GetInt64Uid(ctx Context) int64

func GetSystem added in v0.5.19

func GetSystem(ctx Context) app.System

func GetToken added in v1.8.98

func GetToken(ctx Context, keys ...string) (string, error)

func GetTokenSource added in v0.5.18

func GetTokenSource(ctx Context) token.Source

func GetUid

func GetUid(ctx Context) string

func HeadInt64

func HeadInt64(ctx Context, key string) int64

func MustGet added in v1.5.8

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

func ParamInt64

func ParamInt64(ctx Context, key string) int64

func QueryInt64

func QueryInt64(ctx Context, key string) int64

func SetInt64Uid added in v1.0.36

func SetInt64Uid(ctx Context, uid int64)

func SetUid added in v0.1.2

func SetUid(ctx Context, uid string)

func TokenReq added in v1.6.7

func TokenReq(ctx Context) (string, error)

func WithHeadOption added in v1.0.1

func WithHeadOption(ctx Context, header *Header)

Types

type Api added in v1.8.20

type Api struct {
	Builder ResponseBuilder
}

func (*Api) GetBuilder added in v1.8.20

func (a *Api) GetBuilder() ResponseBuilder

func (*Api) SendEx added in v1.8.20

func (a *Api) SendEx(ctx Context, httpCode int, result result.Result, data interface{}, opts ...option.Option)

func (*Api) SendException added in v1.8.20

func (a *Api) SendException(ctx Context, httpCode int, req request.HeadV2, opts ...option.Option)

func (*Api) SendHead added in v1.8.20

func (a *Api) SendHead(ctx Context, httpCode int, req request.HeadV2, result result.Result, data interface{}, opts ...option.Option)

func (*Api) SendMaybeError added in v1.8.20

func (a *Api) SendMaybeError(ctx Context, httpCode int, data interface{}, err error, opts ...option.Option)

func (*Api) SendNHead added in v1.8.20

func (a *Api) SendNHead(ctx Context, httpCode int, result result.Result, data interface{}, opts ...option.Option)

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 {
	MustGet(key string) 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 EventType added in v1.8.38

type EventType int32

func WithEventType added in v1.8.38

func WithEventType(e int32) EventType

func (EventType) String added in v1.8.38

func (t EventType) String() string

func (EventType) Type added in v1.8.38

func (t EventType) Type() int

func (EventType) Value added in v1.8.38

func (t EventType) Value() interface{}

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 interface{})
	Abort()
	Next()
	Param(key string) string
	Query(key string) string
	ClientIP() string
}

type PageOption added in v1.8.38

type PageOption struct {
	Total int64
	Page  int
	Size  int
}

func PageExist added in v1.8.38

func PageExist(opts ...option.Option) (PageOption, bool)

func WithPageOption added in v1.8.38

func WithPageOption(total int64) PageOption

func (PageOption) String added in v1.8.38

func (t PageOption) String() string

func (PageOption) Type added in v1.8.38

func (t PageOption) Type() int

func (PageOption) Value added in v1.8.38

func (t PageOption) Value() interface{}

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)
	Total     int64       `json:"total,omitempty"`
	Page      int         `json:"page,omitempty"`
	Size      int         `json:"size,omitempty"`
	Data      interface{} `json:"data,omitempty"` //业务具体数据
}

func NewResponse

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

func NewResponseWithError added in v0.5.19

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

type ResponseBuilder added in v1.8.20

type ResponseBuilder interface {
	BuildError(head request.HeadV2, err error, data interface{}, opts ...option.Option) interface{}
	Build(head request.HeadV2, result result.Result, data interface{}, opts ...option.Option) interface{}
	Succeed() result.Result
}

Jump to

Keyboard shortcuts

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