diff --git a/CHANGELOG.md b/CHANGELOG.md index 24900ae..c1c3bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/request_information.go b/request_information.go index 7a99e6b..c2d6715 100644 --- a/request_information.go +++ b/request_information.go @@ -108,9 +108,9 @@ 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)) @@ -118,7 +118,6 @@ func (request *RequestInformation) AddRequestOptions(options ...RequestOption) e 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. @@ -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 + } +}