Skip to content

Commit

Permalink
feat(config): add TransportFactoryFunc type
Browse files Browse the repository at this point in the history
  • Loading branch information
bounoable committed Dec 13, 2020
1 parent 94190f0 commit 79a5129
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type TransportFactory interface {
Transport(context.Context, map[string]interface{}) (postdog.Transport, error)
}

// TransportFactoryFunc allows functions to be used as TransportFactories.
type TransportFactoryFunc func(context.Context, map[string]interface{}) (postdog.Transport, error)

type rawConfig struct {
Transports map[string]Transport `yaml:"transports"`
}
Expand Down Expand Up @@ -123,3 +126,8 @@ func (cfg *Config) Dog(ctx context.Context, opts ...Option) (*postdog.Dog, error

return postdog.New(dogOpts...), nil
}

// Transport accepts the transport-specific configuration and instantiates a transport from that configuration.
func (fn TransportFactoryFunc) Transport(ctx context.Context, m map[string]interface{}) (postdog.Transport, error) {
return fn(ctx, m)
}

0 comments on commit 79a5129

Please sign in to comment.