Skip to content

Commit

Permalink
chore(storage): add makeStorageOpts helper (#6426)
Browse files Browse the repository at this point in the history
This takes out a few lines of boilerplate that will be
present in all top-level methods.
  • Loading branch information
tritone authored Jul 26, 2022
1 parent be23ac8 commit 6cf62f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 14 additions & 0 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ func callSettings(defaults *settings, opts ...storageOption) *settings {
return &cs
}

// makeStorageOpts is a helper for generating a set of storageOption based on
// idempotency, retryConfig, and userProject. All top-level client operations
// will generally have to pass these options through the interface.
func makeStorageOpts(isIdempotent bool, retry *retryConfig, userProject string) []storageOption {
opts := []storageOption{idempotent(isIdempotent)}
if retry != nil {
opts = append(opts, withRetryConfig(retry))
}
if userProject != "" {
opts = append(opts, withUserProject(userProject))
}
return opts
}

// storageOption is the transport-agnostic call option for the storageClient
// interface.
type storageOption interface {
Expand Down
9 changes: 1 addition & 8 deletions storage/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,6 @@ func (c *Composer) Run(ctx context.Context) (attrs *ObjectAttrs, err error) {
}

isIdempotent := c.dst.conds != nil && (c.dst.conds.GenerationMatch != 0 || c.dst.conds.DoesNotExist)
opts := []storageOption{idempotent(isIdempotent)}
if c.dst.retry != nil {
opts = append(opts, withRetryConfig(c.dst.retry))
}
if c.dst.userProject != "" {
opts = append(opts, withUserProject(c.dst.userProject))
}

opts := makeStorageOpts(isIdempotent, c.dst.retry, c.dst.userProject)
return c.dst.c.tc.ComposeObject(ctx, req, opts...)
}

0 comments on commit 6cf62f8

Please sign in to comment.