request

package
v0.0.0-...-8e1814b Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidMethod

func IsValidMethod(method string) bool

IsValidMethod returns whether the supplied method is supported

Types

type Job

type Job struct {
	Request       *http.Request
	Method        string
	Path          string
	Headers       map[string]string
	Body          io.Reader
	Result        interface{}
	JobResult     chan *JobResult
	AuthRequest   bool
	Verbose       bool
	HTTPDebugging bool
}

Job holds a request job

type JobResult

type JobResult struct {
	Error  error
	Result interface{}
}

JobResult holds a request job result

type RateLimit

type RateLimit struct {
	Duration time.Duration
	Rate     int
	Requests int
	Mutex    sync.Mutex
}

RateLimit struct

func NewRateLimit

func NewRateLimit(d time.Duration, rate int) *RateLimit

NewRateLimit creates a new RateLimit

func (*RateLimit) GetDuration

func (r *RateLimit) GetDuration() time.Duration

GetDuration gets the duration for the ratelimit

func (*RateLimit) GetRate

func (r *RateLimit) GetRate() int

GetRate returns the ratelimit rate

func (*RateLimit) GetRequests

func (r *RateLimit) GetRequests() int

GetRequests returns the number of requests for the ratelimit

func (*RateLimit) SetDuration

func (r *RateLimit) SetDuration(d time.Duration)

SetDuration sets the duration for the ratelimit

func (*RateLimit) SetRate

func (r *RateLimit) SetRate(rate int)

SetRate sets the ratelimit rate

func (*RateLimit) SetRequests

func (r *RateLimit) SetRequests(l int)

SetRequests sets requests counter for the rateliit

func (*RateLimit) ToString

func (r *RateLimit) ToString() string

ToString returns the rate limiter in string notation

type Requester

type Requester struct {
	HTTPClient  *http.Client
	UnauthLimit *RateLimit
	AuthLimit   *RateLimit
	Name        string
	UserAgent   string
	Cycle       time.Time

	Jobs chan Job

	WorkerStarted bool
	// contains filtered or unexported fields
}

Requester struct for the request client

var (
	Request *Requester
)

func New

func New(name string, authLimit, unauthLimit *RateLimit, httpRequester *http.Client) *Requester

New returns a new Requester

func (*Requester) DecrementRequests

func (r *Requester) DecrementRequests(auth bool)

DecrementRequests decrements the ratelimiter request counter for either auth or unauth requests 减量计数器

func (*Requester) DoRequest

func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, result interface{}, authRequest, verbose, httpDebug bool) error

DoRequest performs a HTTP/HTTPS request with the supplied params

func (*Requester) GetRateLimit

func (r *Requester) GetRateLimit(auth bool) *RateLimit

GetRateLimit gets the request Requester ratelimiter

func (*Requester) IncrementRequests

func (r *Requester) IncrementRequests(auth bool)

IncrementRequests increments the ratelimiter request counter for either auth or unauth requests 增量计数器

func (*Requester) IsRateLimited

func (r *Requester) IsRateLimited(auth bool) bool

IsRateLimited returns whether or not the request Requester is rate limited

func (*Requester) IsValidCycle

func (r *Requester) IsValidCycle(auth bool) bool

IsValidCycle checks to see whether the current request cycle is valid or not

func (*Requester) RequiresRateLimiter

func (r *Requester) RequiresRateLimiter() bool

RequiresRateLimiter returns whether or not the request Requester requires a rate limiter

func (*Requester) SendPayload

func (r *Requester) SendPayload(method, path string, headers map[string]string, body io.Reader, result interface{}, authRequest, nonceEnabled, verbose, httpDebugging bool) error

SendPayload handles sending HTTP/HTTPS requests

func (*Requester) SetProxy

func (r *Requester) SetProxy(p *url.URL) error

SetProxy sets a proxy address to the client transport

func (*Requester) SetRateLimit

func (r *Requester) SetRateLimit(auth bool, duration time.Duration, rate int)

SetRateLimit sets the request Requester ratelimiter

func (*Requester) SetTimeoutRetryAttempts

func (r *Requester) SetTimeoutRetryAttempts(n int) error

SetTimeoutRetryAttempts sets the amount of times the job will be retried if it times out

func (*Requester) StartCycle

func (r *Requester) StartCycle()

StartCycle restarts the cycle time and requests counters

func (*Requester) WebGETSendPayload

func (r *Requester) WebGETSendPayload(configParam string, params url.Values, result interface{}, authRequest, nonceEnabled, verbose, httpDebugging bool) error

WebGETSendPayload 封装统一请求微服务的 GET 方法

func (*Requester) WebPOSTSendPayload

func (r *Requester) WebPOSTSendPayload(configParam string, body io.Reader, result interface{}, authRequest, nonceEnabled, verbose, httpDebugging bool) error

WebPOSTSendPayload 封装统一请求微服务的 POST 方法

Jump to

Keyboard shortcuts

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