Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*gorequest.SuperAgent不是线程安全的 #1

Open
shuff1e opened this issue Dec 14, 2021 · 1 comment
Open

*gorequest.SuperAgent不是线程安全的 #1

shuff1e opened this issue Dec 14, 2021 · 1 comment

Comments

@shuff1e
Copy link

shuff1e commented Dec 14, 2021

client-go中

type RESTClient struct {
	// base is the root URL for all invocations of the client
	base *url.URL
	// versionedAPIPath is a path segment connecting the base URL to the resource root
	versionedAPIPath string

	// content describes how a RESTClient encodes and decodes responses.
	content ClientContentConfig

	// creates BackoffManager that is passed to requests.
	createBackoffMgr func() BackoffManager

	// rateLimiter is shared among all requests created by this client unless specifically
	// overridden.
	rateLimiter flowcontrol.RateLimiter

	// warningHandler is shared among all requests created by this client.
	// If not set, defaultWarningHandler is used.
	warningHandler WarningHandler

	// Set specific behavior of the client.  If not set http.DefaultClient will be used.
	Client *http.Client
}

*http.Client是线程安全的。


但是

type RESTClient struct {
	// base is the root URL for all invocations of the client
	base *url.URL
	// group stand for the client group, eg: iam.api, iam.authz
	group string
	// versionedAPIPath is a path segment connecting the base URL to the resource root
	versionedAPIPath string
	// content describes how a RESTClient encodes and decodes responses.
	content ClientContentConfig
	Client  *gorequest.SuperAgent
}

*gorequest.SuperAgent不是线程安全的。

@shuff1e
Copy link
Author

shuff1e commented Dec 14, 2021

// Verb begins a Verb request.
func (c *RESTClient) Verb(verb string) *Request {
	return NewRequest(c).Verb(verb)
}

改成

// Verb begins a Verb request.
func (c *RESTClient) Verb(verb string) *Request {
	return NewRequest(c.Clone()).Verb(verb)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant