v0.0.0-...-6e2e2aa Latest Latest

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 14 Imported by: 0



this package is a basic implementation of APIClient



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


View Source
var BaseURL = url.URL{
	Scheme: "https",
	Host:   "",


func FakeUA

func FakeUA(ua apitypes.UserAgentType) string


type Client

type Client struct {
	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