client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = new(Client)

Default client

View Source
var DefaultAPIInitialVector []byte = getenvBase64("CIWEIMAO_API_INITIAL_VECTOR")
View Source
var DefaultAPIKey string = os.Getenv("CIWEIMAO_API_KEY")
View Source
var DefaultAccount string = os.Getenv("CIWEIMAO_ACCOUNT")
View Source
var DefaultAppVersion string = os.Getenv("CIWEIMAO_APP_VERSION")
View Source
var DefaultDeviceToken string = os.Getenv("CIWEIMAO_DEVICE_TOKEN")
View Source
var DefaultLoginToken string = os.Getenv("CIWEIMAO_LOGIN_TOKEN")
View Source
var DefaultPassword string = os.Getenv("CIWEIMAO_PASSWORD")
View Source
var DefaultServerURL string = os.Getenv("CIWEIMAO_SERVER_URL")
View Source
var DefaultUserAgent = os.Getenv("CIWEIMAO_USER_AGENT")

DefaultUserAgent for new clients

View Source
var DefaultUsername string = os.Getenv("CIWEIMAO_USERNAME")

Functions

func ParseTime

func ParseTime(v string) (ret time.Time, err error)

func SkipTokenRefresh added in v0.2.0

func SkipTokenRefresh(ctx context.Context) bool

func With

func With(ctx context.Context, v *Client) context.Context

With set client to context.

func WithSkipTokenRefresh added in v0.2.0

func WithSkipTokenRefresh(ctx context.Context, v bool) context.Context

Types

type Client

type Client struct {
	APIInitialVector []byte
	APIKey           string
	ServerURL        string
	LoginToken       string
	DeviceToken      string
	Account          string
	AppVersion       string
	TokenRefresher   TokenRefresher

	http.Client
	// contains filtered or unexported fields
}

func For

func For(ctx context.Context) *Client

For get client from context.

func (*Client) ApplyDefaultConfig

func (c *Client) ApplyDefaultConfig()

func (*Client) Call

func (c *Client) Call(ctx context.Context, endpoint string, data url.Values) (ret gjson.Result, err error)

func (*Client) DecryptAPIResponse

func (c *Client) DecryptAPIResponse(r io.Reader) (ret io.Reader, err error)

func (*Client) EndpointURL

func (c *Client) EndpointURL(path string, values *url.Values) *url.URL

EndpointURL returns url for server endpint.

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) (ret gjson.Result, err error)

func (*Client) SetDefaultAPIAuthData

func (c *Client) SetDefaultAPIAuthData(data url.Values)

func (*Client) SetDefaultHeader

func (c *Client) SetDefaultHeader(key, value string)

SetDefaultHeader for all requests

func (*Client) SetRequestOptions

func (c *Client) SetRequestOptions(options ...RequestOption)

SetRequestOptions for all requests

type RequestOption

type RequestOption = func(req *http.Request)

RequestOption can mutate request before actual send it.

type RequestOptionsTransport

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

RequestOptionsTransport allow change request before do it.

func (*RequestOptionsTransport) RoundTrip

func (t *RequestOptionsTransport) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip implements http.RoundTripper

type TokenRefreshFunc added in v0.2.0

type TokenRefreshFunc func(ctx context.Context, c *Client) (err error)

func (TokenRefreshFunc) RefreshToken added in v0.2.0

func (fn TokenRefreshFunc) RefreshToken(ctx context.Context, c *Client) error

type TokenRefresher added in v0.2.0

type TokenRefresher interface {
	RefreshToken(ctx context.Context, c *Client) (err error)
}

TokenRefresher refresh login token on demand. use custom logic to store refreshed Client.LoginToken

func NewLoginTokenRefresher added in v0.2.0

func NewLoginTokenRefresher(username, password string) TokenRefresher

Jump to

Keyboard shortcuts

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