api

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Zlib Imports: 11 Imported by: 3

Documentation

Index

Constants

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 (
	CSysVer   = "sysver"
	CDeviceId = "deviceid"
	CModel    = "model"
	CWifi     = "wifi"
	CChannel  = "channel"
	CExtInfo  = "extinfo"
	CTerminal = "terminal"
	CAppId    = "appid"
	CVersion  = "version"
	CSeqid    = "seqid"
	CSource   = "source"
	CToken    = "authorization"
)

Variables

View Source
var (
	DkReq  = Key{"REQ", "it is api.Request object"}
	DkBase = Key{"BASE", "it is api.Base object"}

	DkToken = Key{"TOKEN", "is req token object"}

	DkUseFileName = Key{"UseFileName", "is true/false"}

	DkUid  = Key{"uid", "http: param 'uid'"}
	DkBiz  = Key{"biz", "http: param 'biz' for file upload"}
	DkType = Key{"type", "http: param 'type' for file upload"}
	DkName = Key{"name", "http: param 'name' for file upload"}
	DkSize = Key{"size", "http: param 'size' for file upload"}
	DkId   = Key{"id", "http: param 'id'"}

	//为分片上传
	DkKey         = Key{"key", "http: param 'key' for file upload"}
	DkChunkNum    = Key{"chunknum", "http: param 'chunknum' for file upload"}
	DkChunkOffset = Key{"chunkoffset", "http: param 'chunkoffset' for file upload"}
	DkChunkSize   = Key{"chunksize", "http: param 'chunksize' for file upload"}
)

Functions

func BindBase

func BindBase(ctx Context)

func BindClientAuth

func BindClientAuth(ctx Context)

func BindServerAuth

func BindServerAuth(ctx Context)

func ChangeHeadSource

func ChangeHeadSource(head *ReqHead)

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 GetAppId

func GetAppId(ctx Context) string

func GetAppVersion

func GetAppVersion(ctx Context) string

func GetClientIP

func GetClientIP(ctx Context) string

func GetContentType

func GetContentType(ctx Context) string

func GetDeviceId

func GetDeviceId(ctx Context) string

func GetPlatform

func GetPlatform(ctx Context) string

func GetSource added in v0.2.0

func GetSource(ctx Context) app.Source

func GetUid

func GetUid(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 SendEx

func SendEx(ctx Context, req request.HeadEx, result result.Result, data interface{})

func SendException

func SendException(ctx Context, req request.HeadEx)

func SetUid added in v0.1.2

func SetUid(ctx Context, uid string)

Types

type Base

type Base struct {
	IP      string
	System  app.System
	AppInfo 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
}
type Header struct {
	ReqHead
	System app.System
	App    app.Info
	Token  string //用户token
}

func NewHeader

func NewHeader(req ReqHead, options ...OptionsHeaderFunc) *Header

func (*Header) HasDeviceId

func (h *Header) HasDeviceId() bool

func (*Header) HasToken

func (h *Header) HasToken() bool

func (*Header) ReadFrom added in v0.1.4

func (h *Header) ReadFrom(ctx HeaderContext)

func (*Header) WriteTo added in v0.1.4

func (h *Header) WriteTo(ctx HeaderContext)

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 Key

type Key struct {
	Key string
	// contains filtered or unexported fields
}

type OptionsHeaderFunc

type OptionsHeaderFunc func(h *Header)

type ReqHead

type ReqHead struct {
	Version string        `json:"version"`
	Source  string        `json:"source"`
	SeqId   string        `json:"seqid"`
	StartT  int64         `json:"timeAt"`
	TimeOut time.Duration `json:"-"`
}

func GetReqHead

func GetReqHead(ctx Context) ReqHead

func (*ReqHead) GetSeqId

func (h *ReqHead) GetSeqId() string

GetSeqId head.ReqHead interface

func (*ReqHead) GetSource

func (h *ReqHead) GetSource() string

GetSource head.ReqHead interface

func (*ReqHead) GetStartTime

func (h *ReqHead) GetStartTime() int64

GetStartTime head.ReqHeadEx interface

func (*ReqHead) GetTimeOut

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

GetTimeOut head.ReqHeadEx interface

func (*ReqHead) GetVersion

func (h *ReqHead) GetVersion() string

GetVersion head.ReqHead interface

func (*ReqHead) SetSource

func (h *ReqHead) SetSource(source string)

SetSource head.ReqHeadEx interface

func (*ReqHead) SetTimeOut

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

SetTimeOut head.ReqHeadEx 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"`
	StartT  int64  `json:"timeAt,omitempty"`
	SpendT  int64  `json:"timeSp,omitempty"` //从服务收到请求到响应完成,所花的时长
	SrTime  int64  `json:"timeSr,omitempty"` //服务器时间,M秒,用于检验对时
}

{ "version": "", "source": "", "seqid":"",

"result":{
  "errno": 0,
  "error": "",
  "data":{}
  }
}

func NewResHead

func NewResHead(res result.Result) ResHead

type Response

type Response struct {
	ResHead
	Data interface{} `json:"data,omitempty"`
}

func NewResponse

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

func (*Response) Print

func (reply *Response) Print(Fun string)

Jump to

Keyboard shortcuts

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