gonet

package
v0.0.0-...-01a1fb0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEBUG = LogLevel(1)
	INFO  = LogLevel(2)
	WARN  = LogLevel(3)
	ERROR = LogLevel(4)
	FATAL = LogLevel(5)
)

Variables

View Source
var DefaultUserAgent string = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"

var DefaultUserAgent string = "abcdefghijklmnopqrstuvwxyz"

View Source
var HTTPRequestHelper = NewRequest()
View Source
var NetHelper = &GoNet{}
View Source
var URLHelper = &GoURL{}

Functions

This section is empty.

Types

type DownloadCallback

type DownloadCallback func(int64, int64)

DownloadCallback is a type alias for OnDownload callback functions

type GoNet

type GoNet struct{}

func (*GoNet) IsPrivateIPv4

func (this *GoNet) IsPrivateIPv4(ip net.IP) bool

func (*GoNet) Ping

func (this *GoNet) Ping(network, address string, timeout time.Duration) error

Ping connects to the address on the named network, using net.DialTimeout, and immediately closes it. It returns the connection error. A nil value means success. For examples of valid values of network and address, see the documentation of net.Dial err := Ping("tcp", "0.0.0.0:8088", time.Second)

func (*GoNet) PortIsAvailable

func (this *GoNet) PortIsAvailable(port int) bool

检查端口是否可用

func (*GoNet) PrivateIPv4

func (this *GoNet) PrivateIPv4() (net.IP, error)

type GoURL

type GoURL struct{}

func (*GoURL) AbsoluteURL

func (this *GoURL) AbsoluteURL(rel, base string) (string, error)

相对路径转绝对路径

func (*GoURL) Clean

func (this *GoURL) Clean(uri string) string

美化 url. 如果没有 scheme,将以斜杠开头

func (*GoURL) HasPrefix

func (this *GoURL) HasPrefix(url string) bool

是否 http:// 或 https:// 开头

func (*GoURL) IsDomainName

func (this *GoURL) IsDomainName(s string) bool

isDomainName checks if a string is a presentation-format domain name (currently restricted to hostname-compatible "preferred name" LDH labels and SRV-like "underscore labels"; see golang.org/issue/12421).

func (*GoURL) Join

func (this *GoURL) Join(str ...string) string

func (*GoURL) RemoveHTTPPrefix

func (this *GoURL) RemoveHTTPPrefix(url string) string

移除 URL 的 HTTP 或 HTTPS 前缀

type LogFunc

type LogFunc func(lvl LogLevel, f string, args ...interface{})

type LogLevel

type LogLevel int

func (LogLevel) String

func (l LogLevel) String() string

type Request

type Request struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest() *Request

创建一个新的实例,并返回指针

func (*Request) AddHeader

func (this *Request) AddHeader(key, value string) *Request

func (*Request) Bytes

func (this *Request) Bytes() ([]byte, error)

func (*Request) Debug

func (this *Request) Debug(debug bool) *Request

func (*Request) DisableCookie

func (this *Request) DisableCookie() *Request

func (*Request) DisableDebug

func (this *Request) DisableDebug() *Request

func (*Request) DisableInsecureTLSSkipVerify

func (this *Request) DisableInsecureTLSSkipVerify() *Request

func (*Request) Dump

func (this *Request) Dump() []byte

func (*Request) EnableCookie

func (this *Request) EnableCookie() *Request

是否使用 cookie

func (*Request) EnableDebug

func (this *Request) EnableDebug() *Request

debug

func (*Request) EnableInsecureTLSSkipVerify

func (this *Request) EnableInsecureTLSSkipVerify() *Request

func (*Request) Error

func (this *Request) Error() error

func (*Request) Fetch

func (this *Request) Fetch(method, rawurl string, requestData io.Reader, hdr http.Header, ctx context.Context) error

func (*Request) GET

func (this *Request) GET(URL string) *Request

func (*Request) JSON

func (this *Request) JSON(v interface{}) error

func (*Request) Logf

func (this *Request) Logf(logf LogFunc) *Request

日志

func (*Request) OnDownload

func (this *Request) OnDownload(f DownloadCallback)

func (*Request) OnRequest

func (this *Request) OnRequest(f RequestCallback)

OnRequest registers a function. Function will be executed on every request made by the Collector

func (*Request) POST

func (this *Request) POST(URL string, requestData map[string]string) *Request

req.POST("http://example.com/login", map[string]string{"username": "admin", "password": "admin"})

func (*Request) POSTMultipart

func (this *Request) POSTMultipart(URL string, requestData map[string][]byte) *Request
	return map[string][]byte{
		"firstname": []byte("one"),
		"lastname":  []byte("two"),
		"email":     []byte("onetwo@example.com"),
		"file":      imgData,
	}
}

req.POSTMultipart("http://localhost:8080/", generateFormData())

func (*Request) POSTRaw

func (this *Request) POSTRaw(URL string, requestData []byte) *Request

payload := []byte(`{"user":{"email":"anon@example.com","password":"mypassword"}}`) req.POSTRaw("http://example.com/login", payload)

func (*Request) Response

func (this *Request) Response() *http.Response

func (*Request) Save

func (this *Request) Save(fileName string) error

func (*Request) SendJSON

func (this *Request) SendJSON(URL string, requestData map[string]string) *Request

func (*Request) SetCharacterEncoding

func (this *Request) SetCharacterEncoding(characterEncoding string) *Request

func (*Request) SetClient

func (this *Request) SetClient(client *http.Client) *Request

func (*Request) SetConnectTimeout

func (this *Request) SetConnectTimeout(connectTimeout time.Duration) *Request

func (*Request) SetContentType

func (this *Request) SetContentType(contentType string) *Request

func (*Request) SetContext

func (this *Request) SetContext(ctx context.Context) *Request

func (*Request) SetCookie

func (this *Request) SetCookie(cookie *http.Cookie) *Request

func (*Request) SetHeader

func (this *Request) SetHeader(headers http.Header) *Request

func (*Request) SetInsecureTLSSkipVerify

func (this *Request) SetInsecureTLSSkipVerify(skip bool) *Request

func (*Request) SetProxy

func (this *Request) SetProxy(proxyURL *url.URL) *Request

func (*Request) SetProxyFunc

func (this *Request) SetProxyFunc(proxy func(*http.Request) (*url.URL, error)) *Request

func (*Request) SetProxyURL

func (this *Request) SetProxyURL(proxyURL string) *Request

设置代理

func (*Request) SetReadWriteTimeout

func (this *Request) SetReadWriteTimeout(readWriteTimeout time.Duration) *Request

func (*Request) SetRetries

func (this *Request) SetRetries(retries int) *Request

func (*Request) SetTimeout

func (this *Request) SetTimeout(timeout time.Duration) *Request

func (*Request) SetUserAgent

func (this *Request) SetUserAgent(userAgent string) *Request

func (*Request) String

func (this *Request) String() (string, error)

func (*Request) UseCookie

func (this *Request) UseCookie(use bool) *Request

func (*Request) XML

func (this *Request) XML(v interface{}) error

type RequestCallback

type RequestCallback func(*http.Request)

RequestCallback is a type alias for OnRequest callback functions

Jump to

Keyboard shortcuts

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