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

Add support for decorate resty.Request #430

Open
lexcao opened this issue Jun 16, 2023 · 0 comments
Open

Add support for decorate resty.Request #430

lexcao opened this issue Jun 16, 2023 · 0 comments

Comments

@lexcao
Copy link

lexcao commented Jun 16, 2023

Is your feature request related to a problem? Please describe.
I want to add custom headers per the request.

Describe the solution you'd like
Support options, then we could add options...Options for every method without breaking existing API

type Options func(*resty.Request)
// GetRequestWithBearerAuth returns a JSON base request configured with an auth token.
func (g *GoCloak) GetRequestWithBearerAuth(ctx context.Context, token string, options...Options) *resty.Request {
	request := g.GetRequest(ctx).
		SetAuthToken(token).
		SetHeader("Content-Type", "application/json")

	for _, option := range options {
		option(request)
	}

	return request
}

// the API may look like this
func (g *GoCloak) Login(ctx context.Context, clientID, clientSecret, realm, username, password string, options...Options) (*JWT, error)

Describe alternatives you've considered
I know there is SetPreRequestHook existed in RestyClient, but it could not be set for a single specific request.

Additional context
I am willing to help.

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