connection

package
v0.0.0-...-59c1118 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2017 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	http.Client
	// contains filtered or unexported fields
}

Client uses `userAgent` and `proxy` on all nequests throughout its life. If you need to change them, simply create a new Client. Please note that your can use this Client concurrently as long as the writer is cincurrent safe. But updating it's configuration is not concurrent safe.

func NewClient

func NewClient(logger logrus.FieldLogger, config ...Conf) (httpClient *Client, err error)

NewClient will use `config` to setup the Client. See helpers.go to find out what you can use. If no configuration has passes, it behaves like a normal client.

func (*Client) Close

func (c *Client) Close() error

Close closes the file

func (*Client) Get

func (c *Client) Get(url string) (written int64, err error)

Get fetches the `url`. It uses a proxy and/or useragent if defined.

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body io.Reader) (req *http.Request, err error)

NewRequest creates the request object and sets the user-agent if is set

func (*Client) Proxy

func (c *Client) Proxy() string

Proxy tells you what proxy is being used in this session

func (*Client) UpdateConf

func (c *Client) UpdateConf(conf Conf)

UpdateConf lets you update the configuration at runtime It panics if the conf variable is nil

func (*Client) UserAgent

func (c *Client) UserAgent() string

UserAgent tells you what user-agent string is being used in this session

type Conf

type Conf func(client *Client)

Conf can be passed to NewClient for customizing the Client. (See helpers.go) You can set the following settings: proxy user-agent timeout

func SetFileOutput

func SetFileOutput(filename string) Conf

SetFileOutput writes the output to a file. It exits the program if the file is not writable This client does not close your file and you should do that yourself.

func SetProxy

func SetProxy(proxy string) Conf

SetProxy can be passed to the NewClient to configure the proxy. Usage: NewClient(SetProxy(url))

func SetTimeout

func SetTimeout(timeout time.Duration) Conf

SetTimeout can be passed to the NewClient to configure connection timeout. Usage: NewClient(SetTimeout(timeout))

func SetUserAgent

func SetUserAgent(userAgent string) Conf

SetUserAgent can be passed to the NewClient to configure the user-agent string. Usage: NewClient(SetUserAgent(userAgent))

func SetWriter

func SetWriter(w io.WriteCloser) Conf

SetWriter defined the output of the operation. The default is stdout. This client does not close your writer and you should do that yourself.

Jump to

Keyboard shortcuts

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