Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
doc: More godoc desc
Browse files Browse the repository at this point in the history
  • Loading branch information
ipfans committed Dec 29, 2020
1 parent 14e8fef commit bf8d522
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ type MemoryStore struct {
expiresTime time.Time
}

// Token returns valid token.
func (s *MemoryStore) Token() string {
if time.Now().Before(s.expiresTime) {
return s.token
}
return ""
}

// Refresh token
func (s *MemoryStore) Refresh(c *Client) (err error) {
r := &TokenRequest{}
if s.refreshToken != "" {
Expand Down
5 changes: 5 additions & 0 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package tuyacloud

import "net/http"

// TokenRequest manages token refresh method.
type TokenRequest struct {
refresh string
}

// Method for Request.Method()
func (t *TokenRequest) Method() string {
return http.MethodGet
}

// SetRefresh refresh token.
func (t *TokenRequest) SetRefresh(token string) {
t.refresh = token
}

// URL for Request.URL()
func (t *TokenRequest) URL() string {
uri := "/v1.0/token"
if t.refresh != "" {
Expand All @@ -24,6 +28,7 @@ func (t *TokenRequest) URL() string {
return uri
}

// TokenResponse for token response from tuya server.
type TokenResponse struct {
ExpireTime int `json:"expire_time"`
UID string `json:"uid"`
Expand Down

0 comments on commit bf8d522

Please sign in to comment.