common

package
v0.0.0-...-276c175 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const RequestDelete = "DELETE"
View Source
const RequestGet = "GET"
View Source
const RequestPost = "POST"
View Source
const RequestPut = "PUT"
View Source
const URLCN = "https://openapi.tuyacn.com"

cn

View Source
const URLEU = "https://openapi.tuyaeu.com"

eu

View Source
const URLIN = "https://openapi.tuyain.com"

in

View Source
const URLUS = "https://openapi.tuyaus.com"

us

Variables

test data example

View Source
var ErrorGetTokenFailed = errors.New("get token failed")
View Source
var LocalToken = Info{Mu: &sync.RWMutex{}}

Functions

func AddBizHeader

func AddBizHeader(req *http.Request, token, sign, timestamp string)

func AddBodyBizHeader

func AddBodyBizHeader(req *http.Request, token, sign, timestamp string)

func AddEasyHeader

func AddEasyHeader(req *http.Request, sign, timestamp string)

func DoAPIRequest

func DoAPIRequest(a APIRequest, resp interface{}) error

func DoRequest

func DoRequest(req *http.Request, resp interface{}) error

func GetBizSign

func GetBizSign(token, timestamp string) string

func GetEasySign

func GetEasySign(timestamp string) string

func GetRefreshToken

func GetRefreshToken() (string, error)

func GetTimestamp

func GetTimestamp() string

func GetToken

func GetToken() (string, error)

func HmacSha256

func HmacSha256(data, key string) string

func NewHTTPRequest

func NewHTTPRequest(a APIRequest) (*http.Request, error)

func SetTestEnv

func SetTestEnv()

func SetToken

func SetToken(token, refreshToken string, expire int)

Types

type APIRequest

type APIRequest interface {
	Method() string
	API() string
}

type ExampleData

type ExampleData struct {
	TestDataAccessID  string
	TestDataAccessKey string

	TestDataUID        string
	TestDataDeviceID   string
	TestDataTimeZoneID string

	TestDataThirdCloudDeviceId string

	TestDataCountryCode    string
	TestDataAppSchema      string
	TestDataTuyaUsername   string
	TestDataTuyaProductId  string
	TestDataParentDeviceId string

	TestDataPassword string

	TestDataSchema string
}

type GetTokenAPIResponse

type GetTokenAPIResponse struct {
	Success bool `json:"success"`
	// error info
	Code int    `json:"code"`
	Msg  string `json:"msg"`

	T      int64 `json:"t"`
	Result struct {
		ExpireTime   int    `json:"expire_time"`
		UID          string `json:"uid"`
		AccessToken  string `json:"access_token"`
		RefreshToken string `json:"refresh_token"`
	} `json:"result"`
}

func GetTokenAPI

func GetTokenAPI() (*GetTokenAPIResponse, error)

type GetTokenReq

type GetTokenReq struct {
}

func (*GetTokenReq) API

func (t *GetTokenReq) API() string

func (*GetTokenReq) Method

func (t *GetTokenReq) Method() string

type Info

type Info struct {
	Token        string
	RefreshToken string
	ExpireAt     time.Time
	Mu           *sync.RWMutex
}

type RefreshTokenReq

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

func (*RefreshTokenReq) API

func (t *RefreshTokenReq) API() string

func (*RefreshTokenReq) Method

func (t *RefreshTokenReq) Method() string

type RefreshTokenResponse

type RefreshTokenResponse struct {
	Success bool `json:"success"`
	// error info
	Code int    `json:"code"`
	Msg  string `json:"msg"`

	T      int64 `json:"t"`
	Result struct {
		ExpireTime   int    `json:"expire_time"`
		UID          string `json:"uid"`
		AccessToken  string `json:"access_token"`
		RefreshToken string `json:"refresh_token"`
	} `json:"result"`
}

func DoRefreshToken

func DoRefreshToken() (*RefreshTokenResponse, error)

DoRefreshToken To refresh token

type RequestBody

type RequestBody interface {
	Body() []byte
}

type TokenManage

type TokenManage interface {
	GetToken() (string, error)
}

TokenLocalManage token of local cache manage

var TokenLocalCache TokenManage = &tokenLocalCache{}

Jump to

Keyboard shortcuts

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