Skip to content

Commit

Permalink
Merge pull request #7 from microsoft/feature/request-options
Browse files Browse the repository at this point in the history
- adds vanity methods to simplify generation for request configuration
  • Loading branch information
andrueastman committed Apr 28, 2022
2 parents 159591d + de901fb commit dc0939d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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
}
}

0 comments on commit dc0939d

Please sign in to comment.