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

- adds vanity methods to simplify generation for request configuration #7

Merged
merged 1 commit into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.5.0] - 2022-04-21

### Added

- Added vanity methods to request options to add headers and options to simplify code generation.

## [0.4.0] - 2022-04-19

### Changed
Expand Down
18 changes: 15 additions & 3 deletions request_information.go
Expand Up @@ -108,17 +108,16 @@ func (request *RequestInformation) SetUri(url u.URL) {
}

// AddRequestOptions adds an option to the request to be read by the middleware infrastructure.
func (request *RequestInformation) AddRequestOptions(options ...RequestOption) error {
func (request *RequestInformation) AddRequestOptions(options []RequestOption) {
if options == nil {
return errors.New("RequestOptions cannot be nil")
return
}
if request.options == nil {
request.options = make(map[string]RequestOption, len(options))
}
for _, option := range options {
request.options[option.GetKey().Key] = option
}
return nil
}

// GetRequestOptions returns the options for this request. Options are unique by type. If an option of the same type is added twice, the last one wins.
Expand Down Expand Up @@ -222,3 +221,16 @@ func (request *RequestInformation) AddQueryParameters(source interface{}) {
}
}
}

//AddRequestHeaders adds request headers to the request.
func (request *RequestInformation) AddRequestHeaders(headersToAdd map[string]string) {
if len(headersToAdd) == 0 {
return
}
if len(request.Headers) == 0 {
request.Headers = make(map[string]string, len(headersToAdd))
}
for key, value := range headersToAdd {
request.Headers[key] = value
}
}