client

package
v0.0.0-...-950254a Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)" +
		" Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.42"
)

Variables

View Source
var (
	ErrInvalidRequestURL = errors.New("invalid request url, we only support https:// or http://")
)

Functions

func DefaultConfigRoot

func DefaultConfigRoot() (string, error)

DefaultConfigRoot will generate the default config path based on the user and his running environment.

Types

type Client

type Client struct {
	*resty.Client
	*Config
}

Client is the wrapper for resty.Client we may provide extra method on this wrapper.

func New

func New(c *Config) (*Client, error)

New will create a resty client with a lot of predefined settings.

func (*Client) CleanCookies

func (c *Client) CleanCookies()

func (*Client) SetDefaultHostname

func (c *Client) SetDefaultHostname(host string)

type Config

type Config struct {
	HTTPS      bool   // If the request was under the https of http.
	Host       string // The request host name.
	UserAgent  string // Custom user agent for mocking as the browser client.
	Proxy      string // The proxy address, such as the http://127.0.0.1:7890, socks://127.0.0.1:7890
	ConfigRoot string // The root config path for whole bookhunter download service.

	// The custom redirect function.
	Redirect resty.RedirectPolicy `json:"-"`
}

Config is the basic configuration for creating the client.

func NewConfig

func NewConfig(rawURL, userAgent, proxy, configRoot string) (*Config, error)

NewConfig will create a config instance by using the request url.

func (*Config) ConfigPath

func (c *Config) ConfigPath() (string, error)

ConfigPath will return a unique path for this download service.

Jump to

Keyboard shortcuts

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