Skip to content

Commit

Permalink
Merge pull request #69 from microsoft/feature/base-request
Browse files Browse the repository at this point in the history
- adds base request builder class
  • Loading branch information
baywet authored Mar 22, 2023
2 parents 22507b4 + 8da6815 commit e918747
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.19.0] - 2023-03-22

### Added

- Adds base request builder class to reduce generated code duplication.

## [0.18.0] - 2023-03-20

### Added
Expand Down
29 changes: 29 additions & 0 deletions base_request_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package abstractions

// BaseRequestBuilder is the base class for all request builders.
type BaseRequestBuilder struct {
// Path parameters for the request
PathParameters map[string]string
// The request adapter to use to execute the requests.
RequestAdapter RequestAdapter
// Url template to use to build the URL for the current request builder
UrlTemplate string
}

// NewBaseRequestBuilder creates a new BaseRequestBuilder instance.
func NewBaseRequestBuilder(requestAdapter RequestAdapter, urlTemplate string, pathParameters map[string]string) *BaseRequestBuilder {
if requestAdapter == nil {
panic("requestAdapter cannot be nil")
}
pathParametersCopy := make(map[string]string)
if pathParameters != nil {
for idx, item := range pathParameters {
pathParametersCopy[idx] = item
}
}
return &BaseRequestBuilder{
RequestAdapter: requestAdapter,
UrlTemplate: urlTemplate,
PathParameters: pathParametersCopy,
}
}

0 comments on commit e918747

Please sign in to comment.