commit
f3b52ca8df
@ -1,12 +1,19 @@
|
||||
package vault
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/vault/api"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
)
|
||||
|
||||
type httpClientKey struct{}
|
||||
|
||||
func HTTPClient(c *http.Client) config.Option {
|
||||
return config.SetOption(httpClientKey{}, c)
|
||||
}
|
||||
|
||||
type configKey struct{}
|
||||
|
||||
func Config(cfg *api.Config) config.Option {
|
||||
|
5
vault.go
5
vault.go
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/vault/api"
|
||||
@ -46,6 +47,10 @@ func (c *vaultConfig) Init(opts ...config.Option) error {
|
||||
cfg = v
|
||||
}
|
||||
|
||||
if v, ok := c.opts.Context.Value(httpClientKey{}).(*http.Client); ok {
|
||||
cfg.HttpClient = v
|
||||
}
|
||||
|
||||
if v, ok := c.opts.Context.Value(timeoutKey{}).(time.Duration); ok {
|
||||
cfg.Timeout = v
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user