Skip to content

Commit

Permalink
simplify config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jul 16, 2024
1 parent 1e96792 commit 133cc52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
6 changes: 1 addition & 5 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1618,11 +1618,7 @@ func (p *Config) PasswordMigrationHook(ctx context.Context) *PasswordMigrationHo
return hook
}

config, err := json.Marshal(p.GetProvider(ctx).Get(ViperKeyPasswordMigrationHook + ".config"))
if err != nil {
return hook
}
hook.Config = config
hook.Config, _ = json.Marshal(p.GetProvider(ctx).Get(ViperKeyPasswordMigrationHook + ".config"))

return hook
}
Expand Down
15 changes: 7 additions & 8 deletions request/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -55,14 +54,14 @@ func NewBuilder(ctx context.Context, config json.RawMessage, deps Dependencies,

c, err := parseConfig(config)
if err != nil {
return nil, fmt.Errorf("could not parse config: %w", err)
return nil, err
}

span.SetAttributes(attribute.String("url", c.URL), attribute.String("method", c.Method))

r, err := retryablehttp.NewRequest(c.Method, c.URL, nil)
if err != nil {
return nil, fmt.Errorf("could bot build request: %w", err)
return nil, err
}

return &Builder{
Expand Down Expand Up @@ -102,17 +101,17 @@ func (b *Builder) addBody(ctx context.Context, body interface{}) (err error) {

tpl, err := b.readTemplate(ctx)
if err != nil {
return fmt.Errorf("could not read template: %w", err)
return err
}

switch contentType {
case ContentTypeForm:
if err = b.addURLEncodedBody(ctx, tpl, body); err != nil {
return fmt.Errorf("could not url-encode body: %w", err)
if err := b.addURLEncodedBody(ctx, tpl, body); err != nil {
return err
}
case ContentTypeJSON:
if err = b.addJSONBody(ctx, tpl, body); err != nil {
return fmt.Errorf("could not JSON-encode body: %w", err)
if err := b.addJSONBody(ctx, tpl, body); err != nil {
return err
}
default:
return errors.New("invalid config - incorrect Content-Type for request with body")
Expand Down

0 comments on commit 133cc52

Please sign in to comment.