ahttp

package
v0.0.3-rc0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ahttp 实现http client 上传数据. 授权方式为自动调用授权,可手动调用,也可以直接调用发送数据接口

Index

Constants

View Source
const (
	CodeSuccess              = 0
	CodeUnknown              = 10000
	CodeParamException       = 10001
	CodeAuthFailed           = 20000
	CodeTokenExpired         = 20001 // 需重新调用auth进行鉴权,获取token
	CodeTokenIsNull          = 20002 // 需重新调用auth进行鉴权,获取token
	CodeTokenCheckFailed     = 20003 // 根据token获取identify信息失败。需重新调用auth进行鉴权,获取token
	CodeUpdateSessionFailed  = 20004
	CodePublishMessageFailed = 30001
	CodeRequestTooMany       = 40000
)

错误码

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthRequest

type AuthRequest struct {
	Version    string `json:"version"`
	ClientID   string `json:"clientId"` // 长度为64字符内,建议以MAC地址或SN码作为clientId. 目前productKey.deviceName
	SignMethod string `json:"signmethod"`
	Sign       string `json:"sign"`
	ProductKey string `json:"productKey"`
	DeviceName string `json:"deviceName"`
	// 校验时间戳15分钟内的请求有效。时间戳格式为数值,单位ms
	// 值为自GMT 1970年1月1日0时0分到当前时间点所经过的毫秒数。
	Timestamp int64 `json:"timestamp"`
}

AuthRequest 鉴权请求

type AuthResponse

type AuthResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Info    struct {
		Token string `json:"token"`
	} `json:"info"`
}

AuthResponse 鉴权回复

type Client

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

Client 客户端

func New

func New(meta infra.MetaTriad, opts ...Option) *Client

New 新建alink http client 默认加签算法: hmacmd5 默认host: https://iot-as-http.cn-shanghai.aliyuncs.com 默认使用 http.DefaultClient

func (*Client) Close

func (sf *Client) Close() error

Close 实现dm.Conn接口

func (*Client) Publish

func (sf *Client) Publish(_uri string, _ byte, payload interface{}) error

Publish push message,payload support []byte and string

func (*Client) Subscribe

func (*Client) Subscribe(string, aiot.ProcDownStream) error

Subscribe 实现dm.Conn接口

func (*Client) UnSubscribe

func (*Client) UnSubscribe(...string) error

UnSubscribe 实现dm.Conn接口

type DataResponse

type DataResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Info    struct {
		MessageID int64 `json:"messageID"`
	} `json:"info"`
}

DataResponse 上报数据回复

type Option

type Option func(c *Client)

Option client option

func WithEndpoint

func WithEndpoint(h string) Option

WithEndpoint 设置Endpoint地址,也就是Host

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient with custom http.Client

func WithLogger

func WithLogger(l logger.Logger) Option

WithLogger 设置日志

func WithSignMethod

func WithSignMethod(method string) Option

WithSignMethod 设置签名方法,目前支持hmacsha1,hmacmd5(默认)

Jump to

Keyboard shortcuts

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