client

package
v0.0.0-...-68d1c55 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 14 Imported by: 3

Documentation

Overview

this package is a basic implementation of APIClient

Index

Constants

View Source
const CookieTmpDir = "/var/tmp/ncmapi_client_cookies"

Variables

View Source
var BaseURL = url.URL{
	Scheme: "https",
	Host:   "music.163.com",
}

Functions

func FakeUA

func FakeUA(ua apitypes.UserAgentType) string

Types

type Client

type Client struct {
	*http.Client
	Config *ClientConfig
}

func Default

func Default() *Client

func NewClient

func NewClient(cfg *ClientConfig) *Client

func (*Client) Cookie

func (c *Client) Cookie(u *url.URL, name string) (*http.Cookie, bool)

func (*Client) Cookies

func (c *Client) Cookies(u *url.URL) []*http.Cookie

func (*Client) HasCookie

func (c *Client) HasCookie(u *url.URL, name string) bool

func (*Client) Req

func (c *Client) Req(method string, url string, data apitypes.H, opt *apitypes.RequestOption) (*apitypes.APIResponse, error)

func (*Client) ReqID

func (c *Client) ReqID(method string, url string, data apitypes.H, opt *apitypes.RequestOption) string

func (*Client) Request

func (c *Client) Request(r *apitypes.APIRequest) (*apitypes.APIResponse, error)

func (*Client) RequestID

func (c *Client) RequestID(r *apitypes.APIRequest) string

func (*Client) SetCookies

func (c *Client) SetCookies(u *url.URL, cookies []*http.Cookie)

func (*Client) SyncCookiesFromLocal

func (c *Client) SyncCookiesFromLocal()

func (*Client) WriteCookies

func (c *Client) WriteCookies(cs []*http.Cookie) error

type ClientConfig

type ClientConfig struct {
	// if true, client will read cookies from local & preserve cookie to local when exit
	PreserveCookies bool

	// logs
	LogHttpRequest  bool
	LogHttpResponse bool
}

func DefaultConfig

func DefaultConfig() *ClientConfig

type ClientErr

type ClientErr struct {
	Msg string
}

func (*ClientErr) Error

func (c *ClientErr) Error() string

Jump to

Keyboard shortcuts

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