model

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_SIGN_METHOD = MD5
	DEFAULT_API_VERSION = "2.0"
	DEFAULT_API_FORMAT  = JSON
)

Variables

This section is empty.

Functions

func AnyToString

func AnyToString(val interface{}) (string, error)

Types

type APIFormat

type APIFormat = string
const (
	JSON APIFormat = "json"
	XML  APIFormat = "xml"
)

type CommonRequest

type CommonRequest struct {
	Method       string    `json:"method,omitempty"`         // API接口名称
	AppKey       string    `json:"app_key,omitempty"`        // TOP分配给应用的AppKey
	TargetAppKey string    `json:"target_app_key,omitempty"` // 被调用的目标AppKey,仅当被调用的API为第三方ISV提供时有效
	SignMethod   string    `json:"sign_method,omitempty"`    // 签名的摘要算法,可选值为:hmac,md5,hmac-sha256。
	Session      string    `json:"session,omitempty"`        // 用户登录授权成功后,TOP颁发给应用的授权信息,详细介绍请点击这里。当此API的标签上注明:“需要授权”,则此参数必传;“不需要授权”,则此参数不需要传;“可选授权”,则此参数为可选
	Timestamp    string    `json:"timestamp,omitempty"`      // 时间戳,格式为yyyy-MM-dd HH:mm:ss,时区为GMT+8,例如:2015-01-01 12:00:00。淘宝API服务端允许客户端请求最大时间误差为10分钟
	Format       APIFormat `json:"format,omitempty"`         // 响应格式。默认为xml格式,可选值:xml,json。
	V            string    `json:"v,omitempty"`              // API协议版本,可选值:2.0
	PartnerId    string    `json:"partner_id,omitempty"`     // 合作伙伴身份标识
	Simplify     bool      `json:"simplify,omitempty"`       // 是否采用精简JSON返回格式,仅当format=json时有效,默认值为:false
}

func NewCommonRequest

func NewCommonRequest(method string, appKey string) *CommonRequest

func (CommonRequest) GetParams

func (c CommonRequest) GetParams() map[string]string

func (*CommonRequest) SetAPIFormat

func (c *CommonRequest) SetAPIFormat(format APIFormat)

func (*CommonRequest) SetSession

func (c *CommonRequest) SetSession(session string)

func (*CommonRequest) SetSignMethod

func (c *CommonRequest) SetSignMethod(method SignMethod)

type CommonResponse

type CommonResponse struct {
	ErrorResponse *ErrorResponse `json:"error_response,omitempty" xml:"error_response,omitempty"` // 请求访问失败时返回的根节点
}

func (CommonResponse) B043C16EB094F65A787F22E6AE0A10BCB7ABDE6D

func (c CommonResponse) B043C16EB094F65A787F22E6AE0A10BCB7ABDE6D()

func (CommonResponse) Error

func (c CommonResponse) Error() error

func (CommonResponse) IsError

func (c CommonResponse) IsError() bool

type ErrorResponse

type ErrorResponse struct {
	XMLName   xml.Name `xml:"error_response"`
	RequestId string   `json:"request_id,omitempty" xml:"request_id,omitempty"` // 平台颁发的每次请求访问的唯一标识
	Code      int      `json:"code,omitempty" xml:"code,omitempty"`             // 请求失败返回的错误码
	Msg       string   `json:"msg,omitempty" xml:"msg,omitempty"`               // 请求失败返回的错误信息
	SubCode   string   `json:"sub_code,omitempty" xml:"sub_code,omitempty"`     // 请求失败返回的子错误码
	SubMsg    string   `json:"sub_msg,omitempty" xml:"sub_msg,omitempty"`       // 请求失败返回的子错误信息
}

func (ErrorResponse) Error

func (c ErrorResponse) Error() string

type File

type File struct {
	io.Reader
	Name string
}

func (File) MultipartFileName

func (f File) MultipartFileName() string

type IRequest

type IRequest interface {
	GetApiMethodName() string
	GetApiParams() url.Values
	NeedMultipart() bool
	GetRawParams() map[string]*Param
}

type IResponse

type IResponse interface {
	B043C16EB094F65A787F22E6AE0A10BCB7ABDE6D()
	IsError() bool
	Error() error
}

type Param

type Param struct {
	// contains filtered or unexported fields
}

func NewFileParam

func NewFileParam(fd *File) *Param

func NewStringParam

func NewStringParam(str string) *Param

func (Param) File

func (p Param) File() *File

func (Param) IsFile

func (p Param) IsFile() bool

func (Param) String

func (p Param) String() string

type Params

type Params map[string]*Param

func NewParams

func NewParams() Params

func (Params) GetRawParams

func (p Params) GetRawParams() map[string]*Param

func (Params) NeedMultipart

func (p Params) NeedMultipart() bool

func (Params) Set

func (p Params) Set(key string, value interface{}) error

type SignMethod

type SignMethod = string
const (
	MD5  SignMethod = "md5"
	HMAC SignMethod = "hmac"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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