utils

package
v0.0.0-...-6e90328 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPBinUtil

type HTTPBinUtil struct {
	Timeout time.Duration
}

HTTPBinUtil get and parse the request header by requesting `http(s)://httpbin.org`

func (HTTPBinUtil) GetRequestHeaders

func (u HTTPBinUtil) GetRequestHeaders() (headers HTTPRequestHeaders, err error)

GetRequestHeaders implements RequestHeadersGetter.GetRequestHeaders

func (HTTPBinUtil) GetRequestHeadersUsingProxy

func (u HTTPBinUtil) GetRequestHeadersUsingProxy(proxyURL string) (headers HTTPRequestHeaders, err error)

GetRequestHeadersUsingProxy implements RequestHeadersGetter.GetRequestHeaderUsingProxy

type HTTPRequestHeaders

type HTTPRequestHeaders struct {
	XForwardedFor string `json:"X-Forwarded-For"` // e.g. "1.2.3.4, 5.6.7.8, 1.2.3.4"
	XRealIP       string `json:"X-Real-Ip"`       // e.g. "1.2.3.4"
	Via           string `json:"Via"`             // e.g. "1.1 squid"
}

HTTPRequestHeaders 代表发起HTTP请求时的请求头部分信息 其中`X-Forwarded-For`和`X-Real-Ip`可以计算出Client的公网IP `Via` 一般是在HTTP请求经由代理转发后增加的字段

func (HTTPRequestHeaders) ParsePublicIP

func (h HTTPRequestHeaders) ParsePublicIP() (net.IP, error)

ParsePublicIP resolves the public IP address of the Client based on Headers First parse the IP of the first record of the `X-Forwarded-For` field parse the `X-Real-Ip` field value if it does not exist If all parsing fails, return nil

type Limiter

type Limiter interface {
	Init()
	Enter()
	Exit()
}

type RateLimiter

type RateLimiter struct {
	// Delay is the duration to wait before do next operation.
	Delay time.Duration
	// Parallelism is the number of the maximum allowed concurrent operate.
	Parallelism int
	// contains filtered or unexported fields
}

RateLimiter contains some rate limit to control the rate of some operations, such as network request frequency, etc.

func (*RateLimiter) Enter

func (l *RateLimiter) Enter()

Enter implements Limiter.Enter.

func (*RateLimiter) Exit

func (l *RateLimiter) Exit()

Exit implements Limiter.Exit.

func (*RateLimiter) Init

func (l *RateLimiter) Init()

Init initializes the private members of RateLimiter.

type RequestHeadersGetter

type RequestHeadersGetter interface {
	GetRequestHeaders() (headers HTTPRequestHeaders, err error)
	GetRequestHeadersUsingProxy(proxyURL string) (headers HTTPRequestHeaders, err error)
}

RequestHeadersGetter 获取HTTP请求头的接口。

Jump to

Keyboard shortcuts

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