netop

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2021 License: MIT Imports: 8 Imported by: 4

README

netop

common net operation helper

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidResponseStatusCode invalid response status code
	ErrInvalidResponseStatusCode = errors.New("invalid response status code")
)

Functions

func Get

func Get(url string, parameters ...RequestParam) (*http.Response, error)

Get send a GET request to server and return response or error

func GetBuffer added in v0.2.0

func GetBuffer(url string, parameters ...RequestParam) (*bytes.Buffer, error)

GetBuffer send a GET request to server and return response buffer or error

func GetBytes

func GetBytes(url string, parameters ...RequestParam) ([]byte, error)

GetBytes send a GET request to server and return response buffer or error

func GetString

func GetString(url string, parameters ...RequestParam) (string, error)

GetString send a GET request to server and return response string or error

func Post added in v0.3.1

func Post(url string, parameters ...RequestParam) (*http.Response, error)

Post send a GET request to server and return response or error

func PostBuffer added in v0.3.1

func PostBuffer(url string, parameters ...RequestParam) (*bytes.Buffer, error)

PostBuffer send a GET request to server and return response buffer or error

func PostBytes added in v0.3.1

func PostBytes(url string, parameters ...RequestParam) ([]byte, error)

PostBytes send a GET request to server and return response buffer or error

func PostString added in v0.3.1

func PostString(url string, parameters ...RequestParam) (string, error)

PostString send a GET request to server and return response string or error

Types

type Param

type Param struct {
	URL              string
	Headers          map[string]string
	Form             url.Values
	Retry            int
	RetryInterval    time.Duration
	LogChannel       chan<- string
	ProgressChannel  chan<- *Progress
	ProgressInterval time.Duration
	ValidStatusCode  map[int]bool
}

Param download parameters

func (Param) Log added in v0.1.1

func (s Param) Log(log string)

Log send log

func (Param) SendProgress added in v0.2.0

func (s Param) SendProgress(progress *Progress)

SendProgress send progress

type Progress added in v0.2.0

type Progress struct {
	Total     int64
	Completed int64
	Speed     int64
	Elapsed   time.Duration
	Remain    time.Duration
}

Progress download progress

type RequestParam

type RequestParam interface {
	// contains filtered or unexported methods
}

RequestParam defines download parameters

func FormData added in v0.3.1

func FormData(key, value string) RequestParam

FormData set formdata

func Header(key, value string) RequestParam

Header set request header

func Log

func Log(logChannel chan<- string) RequestParam

Log set log chan to show operation log

func OnProgress added in v0.2.0

func OnProgress(progressChannel chan<- *Progress, interval time.Duration) RequestParam

OnProgress send download progress

func Refer

func Refer(refer string) RequestParam

Refer set request refer

func Retry

func Retry(retry int, interval time.Duration) RequestParam

Retry set request retry times and interval

func ValidStatusCode added in v0.3.1

func ValidStatusCode(statusCodes ...int) RequestParam

ValidStatusCode set valid response status code, otherwise error returned.

Jump to

Keyboard shortcuts

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