Compare commits
1 Commits
v0.0.1
...
1416ab1b3a
| Author | SHA1 | Date | |
|---|---|---|---|
| 1416ab1b3a |
17
.drone.yml
17
.drone.yml
@@ -1,6 +1,17 @@
|
|||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: default
|
name: default
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: vault
|
||||||
|
image: vault:1.7.1
|
||||||
|
environment:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: dev
|
||||||
|
VAULT_DEV_LISTEN_ADDRESS: 0.0.0.0:8200
|
||||||
|
- name: etcd
|
||||||
|
image: bitnami/etcd:3
|
||||||
|
environment:
|
||||||
|
ALLOW_NONE_AUTHENTICATION: yes
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
VAULT_DEV_LISTEN_ADDRESS: http://vault:8200
|
VAULT_DEV_LISTEN_ADDRESS: http://vault:8200
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: dev
|
VAULT_DEV_ROOT_TOKEN_ID: dev
|
||||||
@@ -10,11 +21,9 @@ steps:
|
|||||||
- name: test
|
- name: test
|
||||||
image: golang
|
image: golang
|
||||||
commands:
|
commands:
|
||||||
# - go test -parallel 10 -race ./...
|
- go test -parallel 10 -race ./...
|
||||||
# - go test -race ./...
|
|
||||||
- go test ./...
|
|
||||||
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
image: golangci/golangci-lint:v1.55
|
image: golangci/golangci-lint:v1.53
|
||||||
commands:
|
commands:
|
||||||
- golangci-lint run
|
- golangci-lint run
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ linters:
|
|||||||
- scopelint
|
- scopelint
|
||||||
- exhaustruct
|
- exhaustruct
|
||||||
- depguard
|
- depguard
|
||||||
- nolintlint
|
|
||||||
#deprecated
|
#deprecated
|
||||||
- structcheck
|
- structcheck
|
||||||
- varcheck
|
- varcheck
|
||||||
@@ -43,8 +42,6 @@ linters:
|
|||||||
- ifshort
|
- ifshort
|
||||||
- nosnakecase
|
- nosnakecase
|
||||||
|
|
||||||
- ireturn # implement provider interface
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
|
|||||||
64
client.go
64
client.go
@@ -8,8 +8,8 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Must(providers ...interface{}) *Client {
|
func Must(namespace, appName string, providers ...interface{}) *Client {
|
||||||
client, err := New(providers...)
|
client, err := New(namespace, appName, providers...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -17,8 +17,10 @@ func Must(providers ...interface{}) *Client {
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(providers ...interface{}) (*Client, error) {
|
func New(namespace, appName string, providers ...interface{}) (*Client, error) {
|
||||||
client := &Client{
|
client := &Client{
|
||||||
|
namespace: namespace,
|
||||||
|
appName: appName,
|
||||||
providers: make([]Provider, len(providers)),
|
providers: make([]Provider, len(providers)),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ func (p *provider) init(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *provider) Watch(ctx context.Context, callback WatchCallback, path ...string) error {
|
func (p *provider) Watch(ctx context.Context, key Key, callback WatchCallback) error {
|
||||||
if err := p.init(ctx); err != nil {
|
if err := p.init(ctx); err != nil {
|
||||||
return fmt.Errorf("init read:%w", err)
|
return fmt.Errorf("init read:%w", err)
|
||||||
}
|
}
|
||||||
@@ -74,21 +76,21 @@ func (p *provider) Watch(ctx context.Context, callback WatchCallback, path ...st
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := watch.Watch(ctx, callback, path...); err != nil {
|
if err := watch.Watch(ctx, key, callback); err != nil {
|
||||||
return fmt.Errorf("factory provider: %w", err)
|
return fmt.Errorf("factory provider: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *provider) Value(ctx context.Context, path ...string) (Value, error) {
|
func (p *provider) Read(ctx context.Context, key Key) (Variable, error) {
|
||||||
if err := p.init(ctx); err != nil {
|
if err := p.init(ctx); err != nil {
|
||||||
return nil, fmt.Errorf("init read:%w", err)
|
return Variable{}, fmt.Errorf("init read:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable, err := p.provider.Value(ctx, path...)
|
variable, err := p.provider.Read(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("factory provider: %w", err)
|
return Variable{}, fmt.Errorf("factory provider: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return variable, nil
|
return variable, nil
|
||||||
@@ -96,43 +98,63 @@ func (p *provider) Value(ctx context.Context, path ...string) (Value, error) {
|
|||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
providers []Provider
|
providers []Provider
|
||||||
|
appName string
|
||||||
|
namespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Name() string {
|
func (c *Client) key(name string) Key {
|
||||||
return "client"
|
return Key{
|
||||||
|
Name: name,
|
||||||
|
AppName: c.appName,
|
||||||
|
Namespace: c.namespace,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value get value by name.
|
// Value get value by name.
|
||||||
func (c *Client) Value(ctx context.Context, path ...string) (Value, error) {
|
// nolint: ireturn
|
||||||
|
func (c *Client) Value(ctx context.Context, name string) (Value, error) {
|
||||||
|
variable, err := c.Variable(ctx, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("variable:%w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return variable.Value, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Variable(ctx context.Context, name string) (Variable, error) {
|
||||||
var (
|
var (
|
||||||
value Value
|
variable Variable
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
key := c.key(name)
|
||||||
|
|
||||||
for _, provider := range c.providers {
|
for _, provider := range c.providers {
|
||||||
value, err = provider.Value(ctx, path...)
|
variable, err = provider.Read(ctx, key)
|
||||||
if err == nil || !(errors.Is(err, ErrValueNotFound) || errors.Is(err, ErrInitFactory)) {
|
if err == nil || !(errors.Is(err, ErrVariableNotFound) || errors.Is(err, ErrInitFactory)) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return value, fmt.Errorf("client failed get value: %w", err)
|
return variable, fmt.Errorf("client failed get variable: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return value, nil
|
return variable, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Watch(ctx context.Context, callback WatchCallback, path ...string) error {
|
func (c *Client) Watch(ctx context.Context, name string, callback WatchCallback) error {
|
||||||
|
key := c.key(name)
|
||||||
|
|
||||||
for idx, prov := range c.providers {
|
for idx, prov := range c.providers {
|
||||||
provider, ok := prov.(WatchProvider)
|
provider, ok := prov.(WatchProvider)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := provider.Watch(ctx, callback, path...)
|
err := provider.Watch(ctx, key, callback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrValueNotFound) || errors.Is(err, ErrInitFactory) {
|
if errors.Is(err, ErrVariableNotFound) || errors.Is(err, ErrInitFactory) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
294
client_example_test.go
Normal file
294
client_example_test.go
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
package config_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/arg"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/env"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/etcd"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/json"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/vault"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/watcher"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/yaml"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleClient_Value() {
|
||||||
|
ctx := context.Background()
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_LISTEN", "8080")
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_HOST", "localhost")
|
||||||
|
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
os.Args = args
|
||||||
|
}()
|
||||||
|
|
||||||
|
os.Args = []string{"main.go", "--host=gitoa.ru"}
|
||||||
|
|
||||||
|
// configure etcd client
|
||||||
|
etcdClient, err := test.NewEtcd(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure vault client
|
||||||
|
vaultClient, err := test.NewVault()
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// read json config
|
||||||
|
jsonConfig := test.ReadFile("config.json")
|
||||||
|
|
||||||
|
config, err := config.New(test.Namespace, test.AppName,
|
||||||
|
arg.New(),
|
||||||
|
env.New(),
|
||||||
|
etcd.NewProvider(etcdClient),
|
||||||
|
vault.NewSecretKV2(vaultClient),
|
||||||
|
json.New(jsonConfig),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dsn, err := config.Value(ctx, "example:dsn")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
port, err := config.Value(ctx, "listen")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
enabled, err := config.Value(ctx, "maintain")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
title, err := config.Value(ctx, "app.name.title")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgValue, err := config.Value(ctx, "cfg")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hostValue, err := config.Value(ctx, "host")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := test.Config{}
|
||||||
|
_ = cfgValue.Unmarshal(&cfg)
|
||||||
|
|
||||||
|
fmt.Printf("dsn from vault: %s\n", dsn.String())
|
||||||
|
fmt.Printf("listen from env: %d\n", port.Int())
|
||||||
|
fmt.Printf("maintain from etcd: %v\n", enabled.Bool())
|
||||||
|
fmt.Printf("title from json: %v\n", title.String())
|
||||||
|
fmt.Printf("struct from json: %+v\n", cfg)
|
||||||
|
fmt.Printf("replace env host by args: %v\n", hostValue.String())
|
||||||
|
// Output:
|
||||||
|
// dsn from vault: pgsql://user@pass:127.0.0.1:5432
|
||||||
|
// listen from env: 8080
|
||||||
|
// maintain from etcd: true
|
||||||
|
// title from json: config title
|
||||||
|
// struct from json: {Duration:21m0s Enabled:true}
|
||||||
|
// replace env host by args: gitoa.ru
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleClient_Watch() {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// configure etcd client
|
||||||
|
etcdClient, err := test.NewEtcd(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_EXAMPLE_ENABLE", "true")
|
||||||
|
|
||||||
|
_, err = etcdClient.KV.Put(ctx, "fdevs/config/example_db_dsn", "pgsql://user@pass:127.0.0.1:5432")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
if _, err = etcdClient.KV.Delete(context.Background(), "fdevs/config/example_db_dsn"); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
watcher, err := config.New(test.Namespace, test.AppName,
|
||||||
|
watcher.New(time.Microsecond, env.New()),
|
||||||
|
watcher.New(time.Microsecond, yaml.NewWatch("test/fixture/config.yaml")),
|
||||||
|
etcd.NewProvider(etcdClient),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
err = watcher.Watch(ctx, "example_enable", func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||||
|
fmt.Println("update ", oldVar.Provider, " variable:", oldVar.Name, ", old: ", oldVar.Value.Bool(), " new:", newVar.Value.Bool())
|
||||||
|
wg.Done()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_EXAMPLE_ENABLE", "false")
|
||||||
|
|
||||||
|
err = watcher.Watch(ctx, "example_db_dsn", func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||||
|
fmt.Println("update ", oldVar.Provider, " variable:", oldVar.Name, ", old: ", oldVar.Value.String(), " new:", newVar.Value.String())
|
||||||
|
wg.Done()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time.AfterFunc(time.Second, func() {
|
||||||
|
if _, err := etcdClient.KV.Put(ctx, "fdevs/config/example_db_dsn", "mysql://localhost:5432"); err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// update env variable: FDEVS_CONFIG_EXAMPLE_ENABLE , old: true new: false
|
||||||
|
// update etcd variable: fdevs/config/example_db_dsn , old: pgsql://user@pass:127.0.0.1:5432 new: mysql://localhost:5432
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleClient_Value_factory() {
|
||||||
|
ctx := context.Background()
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_LISTEN", "8080")
|
||||||
|
_ = os.Setenv("FDEVS_CONFIG_HOST", "localhost")
|
||||||
|
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
os.Args = args
|
||||||
|
}()
|
||||||
|
|
||||||
|
os.Args = []string{"main.go", "--config-json=config.json", "--config-yaml=test/fixture/config.yaml"}
|
||||||
|
|
||||||
|
config, err := config.New(test.Namespace, test.AppName,
|
||||||
|
arg.New(),
|
||||||
|
env.New(),
|
||||||
|
config.Factory(func(ctx context.Context, cfg config.ReadConfig) (config.Provider, error) {
|
||||||
|
val, err := cfg.Value(ctx, "config-json")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed read config file:%w", err)
|
||||||
|
}
|
||||||
|
jsonConfig := test.ReadFile(val.String())
|
||||||
|
|
||||||
|
return json.New(jsonConfig), nil
|
||||||
|
}),
|
||||||
|
config.Factory(func(ctx context.Context, cfg config.ReadConfig) (config.Provider, error) {
|
||||||
|
val, err := cfg.Value(ctx, "config-yaml")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed read config file:%w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
provader, err := yaml.NewFile(val.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed init by file %v:%w", val.String(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return provader, nil
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
port, err := config.Value(ctx, "listen")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
title, err := config.Value(ctx, "app.name.title")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
yamlTitle, err := config.Value(ctx, "app/title")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgValue, err := config.Value(ctx, "cfg")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := test.Config{}
|
||||||
|
_ = cfgValue.Unmarshal(&cfg)
|
||||||
|
|
||||||
|
fmt.Printf("listen from env: %d\n", port.Int())
|
||||||
|
fmt.Printf("title from json: %v\n", title.String())
|
||||||
|
fmt.Printf("yaml title: %v\n", yamlTitle.String())
|
||||||
|
fmt.Printf("struct from json: %+v\n", cfg)
|
||||||
|
// Output:
|
||||||
|
// listen from env: 8080
|
||||||
|
// title from json: config title
|
||||||
|
// yaml title: yaml title
|
||||||
|
// struct from json: {Duration:21m0s Enabled:true}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ version: '3'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
vault:
|
vault:
|
||||||
image: vault:1.13.3
|
image: vault:latest
|
||||||
cap_add:
|
cap_add:
|
||||||
- IPC_LOCK
|
- IPC_LOCK
|
||||||
ports:
|
ports:
|
||||||
@@ -10,7 +10,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: "dev"
|
VAULT_DEV_ROOT_TOKEN_ID: "dev"
|
||||||
etcd:
|
etcd:
|
||||||
image: bitnami/etcd:3.5.11
|
image: bitnami/etcd
|
||||||
environment:
|
environment:
|
||||||
ALLOW_NONE_AUTHENTICATION: "yes"
|
ALLOW_NONE_AUTHENTICATION: "yes"
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
9
error.go
9
error.go
@@ -3,9 +3,8 @@ package config
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrValueNotFound = errors.New("value not found")
|
ErrVariableNotFound = errors.New("variable not found")
|
||||||
ErrInvalidValue = errors.New("invalid value")
|
ErrInvalidValue = errors.New("invalid value")
|
||||||
ErrUnknowType = errors.New("unknow type")
|
ErrUnknowType = errors.New("unknow type")
|
||||||
ErrInitFactory = errors.New("init factory")
|
ErrInitFactory = errors.New("init factory")
|
||||||
ErrStopWatch = errors.New("stop watch")
|
|
||||||
)
|
)
|
||||||
|
|||||||
14
go.mod
14
go.mod
@@ -1,3 +1,15 @@
|
|||||||
module gitoa.ru/go-4devs/config
|
module gitoa.ru/go-4devs/config
|
||||||
|
|
||||||
go 1.21
|
go 1.16
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/hashicorp/vault/api v1.1.0
|
||||||
|
github.com/pelletier/go-toml v1.9.0
|
||||||
|
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||||
|
github.com/stretchr/testify v1.7.0
|
||||||
|
github.com/tidwall/gjson v1.7.5
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.0-alpha.0
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.0-alpha.0
|
||||||
|
gopkg.in/ini.v1 v1.62.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||||
|
)
|
||||||
|
|||||||
317
go.sum
317
go.sum
@@ -0,0 +1,317 @@
|
|||||||
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||||
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||||
|
github.com/armon/go-metrics v0.3.0/go.mod h1:zXjbSimjXTd7vOpY8B0/2LpvNvDoXBuplAD+gJD3GYs=
|
||||||
|
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||||
|
github.com/aws/aws-sdk-go v1.25.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
|
||||||
|
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
|
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||||
|
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.1.0 h1:kq/SbG2BCKLkDKkjQf5OWwKWUKj1lgs3lFI4PxnR5lg=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
|
||||||
|
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||||
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
|
github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
|
||||||
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-ldap/ldap/v3 v3.1.3/go.mod h1:3rbOH3jRS2u6jg2rJnKAMLE/xQyCKIveG2Sa/Cohzb8=
|
||||||
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
|
github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||||
|
github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw=
|
||||||
|
github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||||
|
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||||
|
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
|
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
|
||||||
|
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
||||||
|
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||||
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||||
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||||
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
|
||||||
|
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
|
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
|
||||||
|
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||||
|
github.com/hashicorp/go-hclog v0.12.0 h1:d4QkX8FRTYaKaCZBoXYY8zJX2BXjWxurN/GA2tkrmZM=
|
||||||
|
github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||||
|
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g=
|
||||||
|
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
|
||||||
|
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
|
||||||
|
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
|
||||||
|
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
|
||||||
|
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
|
||||||
|
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
|
||||||
|
github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc=
|
||||||
|
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
|
||||||
|
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
|
||||||
|
github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
|
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
|
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||||
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
|
github.com/hashicorp/vault/api v1.1.0 h1:QcxC7FuqEl0sZaIjcXB/kNEeBa0DH5z57qbWBvZwLC4=
|
||||||
|
github.com/hashicorp/vault/api v1.1.0/go.mod h1:R3Umvhlxi2TN7Ex2hzOowyeNb+SfbVWI973N+ctaFMk=
|
||||||
|
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267 h1:e1ok06zGrWJW91rzRroyl5nRNqraaBe4d5hiKcVZuHM=
|
||||||
|
github.com/hashicorp/vault/sdk v0.1.14-0.20200519221838-e0cfd64bc267/go.mod h1:WX57W2PwkrOPQ6rVQk+dy5/htHIaB4aBM70EwKThu10=
|
||||||
|
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
|
||||||
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
|
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||||
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
|
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||||
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
||||||
|
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||||
|
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||||
|
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
|
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||||
|
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||||
|
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||||
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/mitchellh/mapstructure v1.3.2 h1:mRS76wmkOn3KkKAyXDu42V+6ebnXWIztFSYGN7GeoRg=
|
||||||
|
github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
|
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||||
|
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||||
|
github.com/pelletier/go-toml v1.9.0 h1:NOd0BRdOKpPf0SxkL3HxSQOG7rNh+4kl6PHcBPFs7Q0=
|
||||||
|
github.com/pelletier/go-toml v1.9.0/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
|
github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I=
|
||||||
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
|
||||||
|
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||||
|
github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||||
|
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
|
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
|
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||||
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
|
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
|
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
|
||||||
|
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
|
||||||
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||||
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tidwall/gjson v1.7.5 h1:zmAN/xmX7OtpAkv4Ovfso60r/BiCi5IErCDYGNJu+uc=
|
||||||
|
github.com/tidwall/gjson v1.7.5/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
|
||||||
|
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||||
|
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
|
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
|
||||||
|
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||||
|
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.0-alpha.0 h1:+e5nrluATIy3GP53znpkHMFzPTHGYyzvJGFCbuI6ZLc=
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw=
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.0-alpha.0 h1:dr1EOILak2pu4Nf5XbRIOCNIBjcz6UmkQd7hHRXwxaM=
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.0-alpha.0/go.mod h1:wKt7jgDgf/OfKiYmCq5WFGxOFAkVMLxiiXgLDFhECr8=
|
||||||
|
go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0 h1:3yLUEC0nFCxw/RArImOyRUI4OAFbg4PFpBbAhSNzKNY=
|
||||||
|
go.etcd.io/etcd/pkg/v3 v3.5.0-alpha.0/go.mod h1:tV31atvwzcybuqejDoY3oaNRTtlD2l/Ot78Pc9w7DMY=
|
||||||
|
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
|
||||||
|
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||||
|
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
|
||||||
|
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||||
|
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
|
||||||
|
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||||
|
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
|
||||||
|
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
||||||
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
||||||
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529 h1:iMGN4xG0cnqj3t+zOM8wUB0BiPKHEwSxEZCvzcbZuvk=
|
||||||
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||||
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=
|
||||||
|
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 h1:bNEHhJCnrwMKNMmOx3yAynp5vs5/gRy+XWFtZFu7NBM=
|
||||||
|
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
||||||
|
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
|
||||||
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884 h1:fiNLklpBwWK1mth30Hlwk+fcdBmIALlgF5iy77O37Ig=
|
||||||
|
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||||
|
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||||
|
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||||
|
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||||
|
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
|
||||||
|
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||||
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
|
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||||
|
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w=
|
||||||
|
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||||
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
|
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||||
|
|||||||
15
key.go
Normal file
15
key.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Key struct {
|
||||||
|
Name string
|
||||||
|
AppName string
|
||||||
|
Namespace string
|
||||||
|
}
|
||||||
|
|
||||||
|
type KeyFactory func(ctx context.Context, key Key) string
|
||||||
|
|
||||||
|
func (k Key) String() string {
|
||||||
|
return k.Namespace + "_" + k.AppName + "_" + k.Name
|
||||||
|
}
|
||||||
32
key/helpers.go
Normal file
32
key/helpers.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package key
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func LastIndex(sep string, factory config.KeyFactory) func(ctx context.Context, key config.Key) (string, string) {
|
||||||
|
return func(ctx context.Context, key config.Key) (string, string) {
|
||||||
|
name := factory(ctx, key)
|
||||||
|
|
||||||
|
idx := strings.LastIndex(name, sep)
|
||||||
|
if idx == -1 {
|
||||||
|
return name, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return name[0:idx], name[idx+len(sep):]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LastIndexField(sep, def string, factory config.KeyFactory) func(ctx context.Context, key config.Key) (string, string) {
|
||||||
|
return func(ctx context.Context, key config.Key) (string, string) {
|
||||||
|
p, k := LastIndex(sep, factory)(ctx, key)
|
||||||
|
if k == "" {
|
||||||
|
return p, def
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, k
|
||||||
|
}
|
||||||
|
}
|
||||||
64
key/helpers_test.go
Normal file
64
key/helpers_test.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package key_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLastIndex(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
cases := map[string]struct {
|
||||||
|
sep string
|
||||||
|
path string
|
||||||
|
field string
|
||||||
|
}{
|
||||||
|
"/secret/with/field/name": {
|
||||||
|
sep: "/",
|
||||||
|
path: "/secret/with/field",
|
||||||
|
field: "name",
|
||||||
|
},
|
||||||
|
"/secret/database:username": {
|
||||||
|
sep: ":",
|
||||||
|
path: "/secret/database",
|
||||||
|
field: "username",
|
||||||
|
},
|
||||||
|
"database:username": {
|
||||||
|
sep: ":",
|
||||||
|
path: "database",
|
||||||
|
field: "username",
|
||||||
|
},
|
||||||
|
"/secret/database-dsn": {
|
||||||
|
sep: ":",
|
||||||
|
path: "/secret/database-dsn",
|
||||||
|
field: "",
|
||||||
|
},
|
||||||
|
"/secret/database--dsn": {
|
||||||
|
sep: "--",
|
||||||
|
path: "/secret/database",
|
||||||
|
field: "dsn",
|
||||||
|
},
|
||||||
|
"/secret/database:dsn": {
|
||||||
|
sep: "--",
|
||||||
|
path: "/secret/database:dsn",
|
||||||
|
field: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for path, data := range cases {
|
||||||
|
k := config.Key{
|
||||||
|
Name: path,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn := key.LastIndex(data.sep, key.Name)
|
||||||
|
ns, field := fn(ctx, k)
|
||||||
|
assert.Equal(t, data.field, field, k)
|
||||||
|
assert.Equal(t, data.path, ns, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
46
key/key.go
Normal file
46
key/key.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package key
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NsAppName(sep string) config.KeyFactory {
|
||||||
|
return func(_ context.Context, key config.Key) string {
|
||||||
|
return strings.Join([]string{key.Namespace, key.AppName, key.Name}, sep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppName(sep string) config.KeyFactory {
|
||||||
|
return func(_ context.Context, key config.Key) string {
|
||||||
|
return strings.Join([]string{key.AppName, key.Name}, sep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrefixName(prefix string, factory config.KeyFactory) config.KeyFactory {
|
||||||
|
return func(ctx context.Context, key config.Key) string {
|
||||||
|
return prefix + factory(ctx, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Name(_ context.Context, key config.Key) string {
|
||||||
|
return key.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
func AliasName(name string, alias string, def config.KeyFactory) config.KeyFactory {
|
||||||
|
return func(ctx context.Context, key config.Key) string {
|
||||||
|
if name == key.Name {
|
||||||
|
return alias
|
||||||
|
}
|
||||||
|
|
||||||
|
return def(ctx, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReplaceAll(oldVal, newVal string, parent config.KeyFactory) config.KeyFactory {
|
||||||
|
return func(ctx context.Context, key config.Key) string {
|
||||||
|
return strings.ReplaceAll(parent(ctx, key), oldVal, newVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
17
provider.go
17
provider.go
@@ -3,18 +3,17 @@ package config
|
|||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
Value(ctx context.Context, path ...string) (Value, error)
|
Read(ctx context.Context, key Key) (Variable, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NamedProvider interface {
|
type WatchCallback func(ctx context.Context, oldVar, newVar Variable)
|
||||||
Name() string
|
|
||||||
Provider
|
|
||||||
}
|
|
||||||
|
|
||||||
type WatchCallback func(ctx context.Context, oldVar, newVar Value) error
|
|
||||||
|
|
||||||
type WatchProvider interface {
|
type WatchProvider interface {
|
||||||
Watch(ctx context.Context, callback WatchCallback, path ...string) error
|
Watch(ctx context.Context, key Key, callback WatchCallback) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Factory func(ctx context.Context, cfg Provider) (Provider, error)
|
type ReadConfig interface {
|
||||||
|
Value(ctx context.Context, name string) (Value, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Factory func(ctx context.Context, cfg ReadConfig) (Provider, error)
|
||||||
|
|||||||
@@ -2,32 +2,28 @@ package arg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
"gitoa.ru/go-4devs/config/value"
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "arg"
|
|
||||||
|
|
||||||
var _ config.Provider = (*Provider)(nil)
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
type Option func(*Provider)
|
type Option func(*Provider)
|
||||||
|
|
||||||
func WithKeyFactory(factory func(s ...string) string) Option {
|
func WithKeyFactory(factory config.KeyFactory) Option {
|
||||||
return func(p *Provider) { p.key = factory }
|
return func(p *Provider) { p.key = factory }
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(opts ...Option) *Provider {
|
func New(opts ...Option) *Provider {
|
||||||
prov := Provider{
|
prov := Provider{
|
||||||
key: func(s ...string) string {
|
key: key.Name,
|
||||||
return strings.Join(s, "-")
|
|
||||||
},
|
|
||||||
args: make(map[string][]string, len(os.Args[1:])),
|
args: make(map[string][]string, len(os.Args[1:])),
|
||||||
name: Name,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -39,8 +35,7 @@ func New(opts ...Option) *Provider {
|
|||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
args map[string][]string
|
args map[string][]string
|
||||||
key func(...string) string
|
key config.KeyFactory
|
||||||
name string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: cyclop
|
// nolint: cyclop
|
||||||
@@ -103,34 +98,45 @@ func (p *Provider) parse() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Name() string {
|
func (p *Provider) Name() string {
|
||||||
return p.name
|
return "arg"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) {
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
return p.key(ctx, key) != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
if err := p.parse(); err != nil {
|
if err := p.parse(); err != nil {
|
||||||
return nil, err
|
return config.Variable{
|
||||||
|
Name: "",
|
||||||
|
Value: nil,
|
||||||
|
Provider: p.Name(),
|
||||||
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := p.key(path...)
|
name := p.key(ctx, key)
|
||||||
if val, ok := p.args[name]; ok {
|
if val, ok := p.args[name]; ok {
|
||||||
switch {
|
switch {
|
||||||
case len(val) == 1:
|
case len(val) == 1:
|
||||||
return value.JString(val[0]), nil
|
return config.Variable{
|
||||||
|
Name: name,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(val[0]),
|
||||||
|
}, nil
|
||||||
default:
|
default:
|
||||||
data, jerr := json.Marshal(val)
|
var yNode yaml.Node
|
||||||
if jerr != nil {
|
|
||||||
return nil, fmt.Errorf("failed load data:%w", jerr)
|
if err := yaml.Unmarshal([]byte("["+strings.Join(val, ",")+"]"), &yNode); err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("arg: failed unmarshal yaml:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return value.Decode(func(v interface{}) error {
|
return config.Variable{
|
||||||
if err := json.Unmarshal(data, v); err != nil {
|
Name: name,
|
||||||
return fmt.Errorf("unmarshal:%w", err)
|
Provider: p.Name(),
|
||||||
}
|
Value: value.Decode(yNode.Decode),
|
||||||
|
}, nil
|
||||||
return nil
|
|
||||||
}), nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("%s:%w", p.Name(), config.ErrValueNotFound)
|
return config.Variable{}, fmt.Errorf("%w: %s", config.ErrVariableNotFound, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package arg_test
|
package arg_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -33,37 +31,18 @@ func TestProvider(t *testing.T) {
|
|||||||
"--end-after=2008-01-02T15:04:05+03:00",
|
"--end-after=2008-01-02T15:04:05+03:00",
|
||||||
}
|
}
|
||||||
read := []test.Read{
|
read := []test.Read{
|
||||||
test.NewRead(8080, "listen"),
|
test.NewRead("listen", 8080),
|
||||||
test.NewRead("config.hcl", "config"),
|
test.NewRead("config", "config.hcl"),
|
||||||
test.NewRead(test.Time("2010-01-02T15:04:05Z"), "start-at"),
|
test.NewRead("start-at", test.Time("2010-01-02T15:04:05Z")),
|
||||||
test.NewReadUnmarshal(&[]string{"http://4devs.io", "https://4devs.io"}, &[]string{}, "url"),
|
test.NewReadUnmarshal("url", &[]string{"http://4devs.io", "https://4devs.io"}, &[]string{}),
|
||||||
test.NewReadUnmarshal(&[]Duration{{time.Minute}, {time.Hour}}, &[]Duration{}, "timeout"),
|
test.NewReadUnmarshal("timeout", &[]time.Duration{time.Minute, time.Hour}, &[]time.Duration{}),
|
||||||
test.NewReadUnmarshal(&[]time.Time{
|
test.NewReadUnmarshal("end-after", &[]time.Time{
|
||||||
test.Time("2009-01-02T15:04:05Z"),
|
test.Time("2009-01-02T15:04:05Z"),
|
||||||
test.Time("2008-01-02T15:04:05+03:00"),
|
test.Time("2008-01-02T15:04:05+03:00"),
|
||||||
}, &[]time.Time{}, "end-after"),
|
}, &[]time.Time{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
prov := arg.New()
|
prov := arg.New()
|
||||||
|
|
||||||
test.Run(t, prov, read)
|
test.Run(t, prov, read)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Duration struct {
|
|
||||||
time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Duration) UnmarshalJSON(in []byte) error {
|
|
||||||
o, err := time.ParseDuration(strings.Trim(string(in), `"`))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("parse:%w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Duration = o
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Duration) MarshalJSON() ([]byte, error) {
|
|
||||||
return []byte(fmt.Sprintf("%q", d)), nil
|
|
||||||
}
|
|
||||||
|
|||||||
35
provider/env/provider.go
vendored
35
provider/env/provider.go
vendored
@@ -2,30 +2,27 @@ package env
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
"gitoa.ru/go-4devs/config/value"
|
"gitoa.ru/go-4devs/config/value"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "env"
|
|
||||||
|
|
||||||
var _ config.Provider = (*Provider)(nil)
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
type Option func(*Provider)
|
type Option func(*Provider)
|
||||||
|
|
||||||
func WithKeyFactory(factory func(...string) string) Option {
|
func WithKeyFactory(factory config.KeyFactory) Option {
|
||||||
return func(p *Provider) { p.key = factory }
|
return func(p *Provider) { p.key = factory }
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(namespace, appName string, opts ...Option) *Provider {
|
func New(opts ...Option) *Provider {
|
||||||
provider := Provider{
|
provider := Provider{
|
||||||
key: func(path ...string) string {
|
key: func(ctx context.Context, k config.Key) string {
|
||||||
return strings.ToUpper(strings.Join(path, "_"))
|
return strings.ToUpper(key.NsAppName("_")(ctx, k))
|
||||||
},
|
},
|
||||||
prefix: strings.ToUpper(namespace + "_" + appName + "_"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -36,20 +33,26 @@ func New(namespace, appName string, opts ...Option) *Provider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
key func(...string) string
|
key config.KeyFactory
|
||||||
name string
|
|
||||||
prefix string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Name() string {
|
func (p *Provider) Name() string {
|
||||||
return p.name
|
return "env"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) {
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
name := p.prefix + p.key(path...)
|
return p.key(ctx, key) != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
name := p.key(ctx, key)
|
||||||
if val, ok := os.LookupEnv(name); ok {
|
if val, ok := os.LookupEnv(name); ok {
|
||||||
return value.JString(val), nil
|
return config.Variable{
|
||||||
|
Name: name,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(val),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("%v:%w", p.Name(), config.ErrValueNotFound)
|
return config.Variable{}, config.ErrVariableNotFound
|
||||||
}
|
}
|
||||||
|
|||||||
6
provider/env/provider_test.go
vendored
6
provider/env/provider_test.go
vendored
@@ -14,11 +14,11 @@ func TestProvider(t *testing.T) {
|
|||||||
os.Setenv("FDEVS_CONFIG_DSN", test.DSN)
|
os.Setenv("FDEVS_CONFIG_DSN", test.DSN)
|
||||||
os.Setenv("FDEVS_CONFIG_PORT", "8080")
|
os.Setenv("FDEVS_CONFIG_PORT", "8080")
|
||||||
|
|
||||||
provider := env.New("fdevs", "config")
|
provider := env.New()
|
||||||
|
|
||||||
read := []test.Read{
|
read := []test.Read{
|
||||||
test.NewRead(test.DSN, "dsn"),
|
test.NewRead("dsn", test.DSN),
|
||||||
test.NewRead(8080, "port"),
|
test.NewRead("port", 8080),
|
||||||
}
|
}
|
||||||
test.Run(t, provider, read)
|
test.Run(t, provider, read)
|
||||||
}
|
}
|
||||||
|
|||||||
109
provider/etcd/provider.go
Normal file
109
provider/etcd/provider.go
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package etcd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
pb "go.etcd.io/etcd/api/v3/mvccpb"
|
||||||
|
client "go.etcd.io/etcd/client/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ config.Provider = (*Provider)(nil)
|
||||||
|
_ config.WatchProvider = (*Provider)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
|
type Client interface {
|
||||||
|
client.KV
|
||||||
|
client.Watcher
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProvider(client Client) *Provider {
|
||||||
|
p := Provider{
|
||||||
|
client: client,
|
||||||
|
key: key.NsAppName("/"),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &p
|
||||||
|
}
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
client Client
|
||||||
|
key config.KeyFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
return p.key(ctx, key) != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Name() string {
|
||||||
|
return "etcd"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
name := p.key(ctx, key)
|
||||||
|
|
||||||
|
resp, err := p.client.Get(ctx, name, client.WithPrefix())
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: key:%s, prov:%s", err, name, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := p.resolve(name, resp.Kvs)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: key:%s, prov:%s", err, name, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
return val, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Watch(ctx context.Context, key config.Key, callback config.WatchCallback) error {
|
||||||
|
go func(ctx context.Context, key string, callback config.WatchCallback) {
|
||||||
|
watch := p.client.Watch(ctx, key, client.WithPrevKV(), client.WithPrefix())
|
||||||
|
for w := range watch {
|
||||||
|
kvs, olds := p.getEventKvs(w.Events)
|
||||||
|
if len(kvs) > 0 {
|
||||||
|
newVar, _ := p.resolve(key, kvs)
|
||||||
|
oldVar, _ := p.resolve(key, olds)
|
||||||
|
callback(ctx, oldVar, newVar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(ctx, p.key(ctx, key), callback)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) getEventKvs(events []*client.Event) ([]*pb.KeyValue, []*pb.KeyValue) {
|
||||||
|
kvs := make([]*pb.KeyValue, 0, len(events))
|
||||||
|
old := make([]*pb.KeyValue, 0, len(events))
|
||||||
|
|
||||||
|
for i := range events {
|
||||||
|
kvs = append(kvs, events[i].Kv)
|
||||||
|
old = append(old, events[i].PrevKv)
|
||||||
|
}
|
||||||
|
|
||||||
|
return kvs, old
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) resolve(key string, kvs []*pb.KeyValue) (config.Variable, error) {
|
||||||
|
for _, kv := range kvs {
|
||||||
|
switch {
|
||||||
|
case kv == nil:
|
||||||
|
return config.Variable{
|
||||||
|
Name: key,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: nil,
|
||||||
|
}, nil
|
||||||
|
case string(kv.Key) == key:
|
||||||
|
return config.Variable{
|
||||||
|
Value: value.JBytes(kv.Value),
|
||||||
|
Name: key,
|
||||||
|
Provider: p.Name(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: name %s", config.ErrVariableNotFound, key)
|
||||||
|
}
|
||||||
119
provider/etcd/provider_test.go
Normal file
119
provider/etcd/provider_test.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package etcd_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/etcd"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
et, err := test.NewEtcd(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
provider := etcd.NewProvider(et)
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewRead("db_dsn", test.DSN),
|
||||||
|
test.NewRead("duration", 12*time.Minute),
|
||||||
|
test.NewRead("port", 8080),
|
||||||
|
test.NewRead("maintain", true),
|
||||||
|
test.NewRead("start_at", test.Time("2020-01-02T15:04:05Z")),
|
||||||
|
test.NewRead("percent", .064),
|
||||||
|
test.NewRead("count", uint(2020)),
|
||||||
|
test.NewRead("int64", int64(2021)),
|
||||||
|
test.NewRead("uint64", int64(2022)),
|
||||||
|
test.NewReadConfig("config"),
|
||||||
|
}
|
||||||
|
test.Run(t, provider, read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func value(cnt int32) string {
|
||||||
|
return fmt.Sprintf("test data: %d", cnt)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWatcher(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
key := config.Key{
|
||||||
|
AppName: "config",
|
||||||
|
Namespace: "fdevs",
|
||||||
|
Name: "test_watch",
|
||||||
|
}
|
||||||
|
|
||||||
|
et, err := test.NewEtcd(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
_, err = et.KV.Delete(context.Background(), "fdevs/config/test_watch")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
|
var cnt, cnt2 int32
|
||||||
|
|
||||||
|
prov := etcd.NewProvider(et)
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(6)
|
||||||
|
|
||||||
|
watch := func(cnt *int32) func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||||
|
return func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||||
|
switch *cnt {
|
||||||
|
case 0:
|
||||||
|
assert.Equal(t, value(*cnt), newVar.Value.String())
|
||||||
|
assert.Nil(t, oldVar.Value)
|
||||||
|
case 1:
|
||||||
|
assert.Equal(t, value(*cnt), newVar.Value.String())
|
||||||
|
assert.Equal(t, value(*cnt-1), oldVar.Value.String())
|
||||||
|
case 2:
|
||||||
|
_, perr := newVar.Value.ParseString()
|
||||||
|
assert.NoError(t, perr)
|
||||||
|
assert.Equal(t, "", newVar.Value.String())
|
||||||
|
assert.Equal(t, value(*cnt-1), oldVar.Value.String())
|
||||||
|
default:
|
||||||
|
assert.Fail(t, "unexpected watch")
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Done()
|
||||||
|
atomic.AddInt32(cnt, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = prov.Watch(ctx, key, watch(&cnt))
|
||||||
|
err = prov.Watch(ctx, key, watch(&cnt2))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
time.AfterFunc(time.Second, func() {
|
||||||
|
_, err = et.KV.Put(ctx, "fdevs/config/test_watch", value(0))
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = et.KV.Put(ctx, "fdevs/config/test_watch", value(1))
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = et.KV.Delete(ctx, "fdevs/config/test_watch")
|
||||||
|
require.NoError(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
time.AfterFunc(time.Second*10, func() {
|
||||||
|
assert.Fail(t, "failed watch after 5 sec")
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-ctx.Done()
|
||||||
|
}
|
||||||
64
provider/ini/provider.go
Normal file
64
provider/ini/provider.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package ini
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
|
func New(data *ini.File) *Provider {
|
||||||
|
const nameParts = 2
|
||||||
|
|
||||||
|
return &Provider{
|
||||||
|
data: data,
|
||||||
|
resolve: func(ctx context.Context, key config.Key) (string, string) {
|
||||||
|
keys := strings.SplitN(key.Name, "/", nameParts)
|
||||||
|
if len(keys) == 1 {
|
||||||
|
return "", keys[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys[0], keys[1]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
data *ini.File
|
||||||
|
resolve func(ctx context.Context, key config.Key) (string, string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
section, name := p.resolve(ctx, key)
|
||||||
|
|
||||||
|
return section != "" && name != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Name() string {
|
||||||
|
return "ini"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
section, name := p.resolve(ctx, key)
|
||||||
|
|
||||||
|
iniSection, err := p.data.GetSection(section)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: %s: %w", config.ErrVariableNotFound, p.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
iniKey, err := iniSection.GetKey(name)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: %s: %w", config.ErrVariableNotFound, p.Name(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{
|
||||||
|
Name: section + ":" + name,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(iniKey.String()),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
28
provider/ini/provider_test.go
Normal file
28
provider/ini/provider_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package ini_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config/provider/ini"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
file := test.NewINI()
|
||||||
|
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewRead("project/PROJECT_BOARD_BASIC_KANBAN_TYPE", "To Do, In Progress, Done"),
|
||||||
|
test.NewRead("repository.editor/PREVIEWABLE_FILE_MODES", "markdown"),
|
||||||
|
test.NewRead("server/LOCAL_ROOT_URL", "http://0.0.0.0:3000/"),
|
||||||
|
test.NewRead("server/LFS_HTTP_AUTH_EXPIRY", 20*time.Minute),
|
||||||
|
test.NewRead("repository.pull-request/DEFAULT_MERGE_MESSAGE_SIZE", 5120),
|
||||||
|
test.NewRead("ui/SHOW_USER_EMAIL", true),
|
||||||
|
test.NewRead("cors/ENABLED", false),
|
||||||
|
}
|
||||||
|
|
||||||
|
prov := ini.New(file)
|
||||||
|
test.Run(t, prov, read)
|
||||||
|
}
|
||||||
66
provider/json/provider.go
Normal file
66
provider/json/provider.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
|
func New(json []byte, opts ...Option) *Provider {
|
||||||
|
provider := Provider{
|
||||||
|
key: key.Name,
|
||||||
|
data: json,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &provider
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFile(path string, opts ...Option) (*Provider, error) {
|
||||||
|
file, err := ioutil.ReadFile(filepath.Clean(path))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: unable to read config file %#q: file not found or unreadable", err, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return New(file, opts...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*Provider)
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
data []byte
|
||||||
|
key config.KeyFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
return p.key(ctx, key) != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Name() string {
|
||||||
|
return "json"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
path := p.key(ctx, key)
|
||||||
|
|
||||||
|
if val := gjson.GetBytes(p.data, path); val.Exists() {
|
||||||
|
return config.Variable{
|
||||||
|
Name: path,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(val.String()),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{}, config.ErrVariableNotFound
|
||||||
|
}
|
||||||
27
provider/json/provider_test.go
Normal file
27
provider/json/provider_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package json_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
provider "gitoa.ru/go-4devs/config/provider/json"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
js := test.ReadFile("config.json")
|
||||||
|
|
||||||
|
prov := provider.New(js)
|
||||||
|
sl := []string{}
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewRead("app.name.title", "config title"),
|
||||||
|
test.NewRead("app.name.timeout", time.Minute),
|
||||||
|
test.NewReadUnmarshal("app.name.var", &[]string{"name"}, &sl),
|
||||||
|
test.NewReadConfig("cfg"),
|
||||||
|
test.NewRead("app.name.success", true),
|
||||||
|
}
|
||||||
|
|
||||||
|
test.Run(t, prov, read)
|
||||||
|
}
|
||||||
71
provider/toml/provider.go
Normal file
71
provider/toml/provider.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package toml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml"
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
|
func NewFile(file string, opts ...Option) (*Provider, error) {
|
||||||
|
tree, err := toml.LoadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("toml: failed load file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return configure(tree, opts...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*Provider)
|
||||||
|
|
||||||
|
func configure(tree *toml.Tree, opts ...Option) *Provider {
|
||||||
|
prov := &Provider{
|
||||||
|
tree: tree,
|
||||||
|
key: key.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(prov)
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(data []byte, opts ...Option) (*Provider, error) {
|
||||||
|
tree, err := toml.LoadBytes(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("toml failed load data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return configure(tree, opts...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
tree *toml.Tree
|
||||||
|
key config.KeyFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
return p.key(ctx, key) != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Name() string {
|
||||||
|
return "toml"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
if k := p.key(ctx, key); p.tree.Has(k) {
|
||||||
|
return config.Variable{
|
||||||
|
Name: k,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: Value{Value: value.Value{Val: p.tree.Get(k)}},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{}, config.ErrVariableNotFound
|
||||||
|
}
|
||||||
29
provider/toml/provider_test.go
Normal file
29
provider/toml/provider_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package toml_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/toml"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
prov, err := toml.NewFile(test.FixturePath("config.toml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
m := []int{}
|
||||||
|
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewRead("database.server", "192.168.1.1"),
|
||||||
|
test.NewRead("title", "TOML Example"),
|
||||||
|
test.NewRead("servers.alpha.ip", "10.0.0.1"),
|
||||||
|
test.NewRead("database.enabled", true),
|
||||||
|
test.NewRead("database.connection_max", 5000),
|
||||||
|
test.NewReadUnmarshal("database.ports", &[]int{8001, 8001, 8002}, &m),
|
||||||
|
}
|
||||||
|
|
||||||
|
test.Run(t, prov, read)
|
||||||
|
}
|
||||||
41
provider/toml/value.go
Normal file
41
provider/toml/value.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package toml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Value struct {
|
||||||
|
value.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Value) Int() int {
|
||||||
|
v, _ := s.ParseInt()
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Value) ParseInt() (int, error) {
|
||||||
|
v, err := s.ParseInt64()
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("toml failed parce int: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(v), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Value) Unmarshal(target interface{}) error {
|
||||||
|
b, err := json.Marshal(s.Raw())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("%w: %w", config.ErrInvalidValue, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(b, target); err != nil {
|
||||||
|
return fmt.Errorf("%w: %w", config.ErrInvalidValue, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
90
provider/vault/secret.go
Normal file
90
provider/vault/secret.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package vault
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/hashicorp/vault/api"
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/key"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*SecretKV2)(nil)
|
||||||
|
|
||||||
|
type SecretOption func(*SecretKV2)
|
||||||
|
|
||||||
|
func WithSecretResolve(f func(context.Context, config.Key) (string, string)) SecretOption {
|
||||||
|
return func(s *SecretKV2) { s.resolve = f }
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSecretKV2(client *api.Client, opts ...SecretOption) *SecretKV2 {
|
||||||
|
prov := SecretKV2{
|
||||||
|
client: client,
|
||||||
|
resolve: key.LastIndexField(":", "value", key.PrefixName("secret/data/", key.NsAppName("/"))),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&prov)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &prov
|
||||||
|
}
|
||||||
|
|
||||||
|
type SecretKV2 struct {
|
||||||
|
client *api.Client
|
||||||
|
resolve func(ctx context.Context, key config.Key) (string, string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SecretKV2) IsSupport(ctx context.Context, key config.Key) bool {
|
||||||
|
path, _ := p.resolve(ctx, key)
|
||||||
|
|
||||||
|
return path != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SecretKV2) Name() string {
|
||||||
|
return "vault"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SecretKV2) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
path, field := p.resolve(ctx, key)
|
||||||
|
|
||||||
|
secret, err := p.client.Logical().Read(path)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: path:%s, field:%s, provider:%s", err, path, field, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
if secret == nil || len(secret.Data) == 0 {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: path:%s, field:%s, provider:%s", config.ErrVariableNotFound, path, field, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(secret.Warnings) > 0 {
|
||||||
|
return config.Variable{},
|
||||||
|
fmt.Errorf("%w: warn: %s, path:%s, field:%s, provider:%s", config.ErrVariableNotFound, secret.Warnings, path, field, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
data, ok := secret.Data["data"].(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: path:%s, field:%s, provider:%s", config.ErrVariableNotFound, path, field, p.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := data[field]; ok {
|
||||||
|
return config.Variable{
|
||||||
|
Name: path + field,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(fmt.Sprint(val)),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
md, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: %w", config.ErrInvalidValue, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{
|
||||||
|
Name: path + field,
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JBytes(md),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
26
provider/vault/secret_test.go
Normal file
26
provider/vault/secret_test.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package vault_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"gitoa.ru/go-4devs/config/provider/vault"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cl, err := test.NewVault()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
provider := vault.NewSecretKV2(cl)
|
||||||
|
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewReadConfig("database"),
|
||||||
|
test.NewRead("db:dsn", test.DSN),
|
||||||
|
test.NewRead("db:timeout", time.Minute),
|
||||||
|
}
|
||||||
|
test.Run(t, provider, read)
|
||||||
|
}
|
||||||
@@ -2,9 +2,8 @@ package watcher
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
@@ -18,8 +17,10 @@ var (
|
|||||||
func New(duration time.Duration, provider config.Provider, opts ...Option) *Provider {
|
func New(duration time.Duration, provider config.Provider, opts ...Option) *Provider {
|
||||||
prov := &Provider{
|
prov := &Provider{
|
||||||
Provider: provider,
|
Provider: provider,
|
||||||
duration: duration,
|
ticker: time.NewTicker(duration),
|
||||||
logger: slog.ErrorContext,
|
logger: func(_ context.Context, msg string) {
|
||||||
|
log.Print(msg)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@@ -29,7 +30,7 @@ func New(duration time.Duration, provider config.Provider, opts ...Option) *Prov
|
|||||||
return prov
|
return prov
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithLogger(l func(context.Context, string, ...any)) Option {
|
func WithLogger(l func(context.Context, string)) Option {
|
||||||
return func(p *Provider) {
|
return func(p *Provider) {
|
||||||
p.logger = l
|
p.logger = l
|
||||||
}
|
}
|
||||||
@@ -39,42 +40,32 @@ type Option func(*Provider)
|
|||||||
|
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
config.Provider
|
config.Provider
|
||||||
duration time.Duration
|
ticker *time.Ticker
|
||||||
logger func(context.Context, string, ...any)
|
logger func(context.Context, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Watch(ctx context.Context, callback config.WatchCallback, key ...string) error {
|
func (p *Provider) Watch(ctx context.Context, key config.Key, callback config.WatchCallback) error {
|
||||||
old, err := p.Provider.Value(ctx, key...)
|
oldVar, err := p.Provider.Read(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed watch variable: %w", err)
|
return fmt.Errorf("failed watch variable: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func(oldVar config.Value) {
|
go func() {
|
||||||
ticker := time.NewTicker(p.duration)
|
|
||||||
defer func() {
|
|
||||||
ticker.Stop()
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-p.ticker.C:
|
||||||
newVar, err := p.Provider.Value(ctx, key...)
|
newVar, err := p.Provider.Read(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger(ctx, "get value%v:%v", key, err.Error())
|
p.logger(ctx, err.Error())
|
||||||
} else if !newVar.IsEquals(oldVar) {
|
} else if !newVar.IsEquals(oldVar) {
|
||||||
if err := callback(ctx, oldVar, newVar); err != nil {
|
callback(ctx, oldVar, newVar)
|
||||||
if errors.Is(err, config.ErrStopWatch) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
p.logger(ctx, "callback %v:%v", key, err)
|
|
||||||
}
|
|
||||||
oldVar = newVar
|
oldVar = newVar
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(old)
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,18 @@ package watcher_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
"gitoa.ru/go-4devs/config/provider/watcher"
|
"gitoa.ru/go-4devs/config/provider/watcher"
|
||||||
"gitoa.ru/go-4devs/config/test/require"
|
|
||||||
"gitoa.ru/go-4devs/config/value"
|
"gitoa.ru/go-4devs/config/value"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ config.Provider = (*provider)(nil)
|
|
||||||
|
|
||||||
type provider struct {
|
type provider struct {
|
||||||
cnt int32
|
cnt int32
|
||||||
}
|
}
|
||||||
@@ -24,20 +22,20 @@ func (p *provider) Name() string {
|
|||||||
return "test"
|
return "test"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *provider) Value(context.Context, ...string) (config.Value, error) {
|
func (p *provider) Read(context.Context, config.Key) (config.Variable, error) {
|
||||||
p.cnt++
|
p.cnt++
|
||||||
|
|
||||||
return value.JString(strconv.Itoa(int(p.cnt))), nil
|
return config.Variable{
|
||||||
|
Name: "tmpname",
|
||||||
|
Provider: p.Name(),
|
||||||
|
Value: value.JString(fmt.Sprint(p.cnt)),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatcher(t *testing.T) {
|
func TestWatcher(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
|
ctx := context.Background()
|
||||||
defer func() {
|
|
||||||
cancel()
|
|
||||||
}()
|
|
||||||
|
|
||||||
prov := &provider{}
|
prov := &provider{}
|
||||||
|
|
||||||
w := watcher.New(time.Second, prov)
|
w := watcher.New(time.Second, prov)
|
||||||
@@ -48,20 +46,14 @@ func TestWatcher(t *testing.T) {
|
|||||||
|
|
||||||
err := w.Watch(
|
err := w.Watch(
|
||||||
ctx,
|
ctx,
|
||||||
func(ctx context.Context, oldVar, newVar config.Value) error {
|
config.Key{Name: "tmpname"},
|
||||||
|
func(ctx context.Context, oldVar, newVar config.Variable) {
|
||||||
atomic.AddInt32(&cnt, 1)
|
atomic.AddInt32(&cnt, 1)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
if atomic.LoadInt32(&cnt) == 2 {
|
|
||||||
return config.ErrStopWatch
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
"tmpname",
|
|
||||||
)
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, int32(2), cnt)
|
require.Equal(t, int32(2), cnt)
|
||||||
}
|
}
|
||||||
|
|||||||
108
provider/yaml/provider.go
Normal file
108
provider/yaml/provider.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package yaml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gitoa.ru/go-4devs/config/value"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*Provider)(nil)
|
||||||
|
|
||||||
|
func keyFactory(_ context.Context, key config.Key) []string {
|
||||||
|
return strings.Split(key.Name, "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFile(name string, opts ...Option) (*Provider, error) {
|
||||||
|
in, err := ioutil.ReadFile(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("yaml_file: read error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return New(in, opts...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(yml []byte, opts ...Option) (*Provider, error) {
|
||||||
|
var data yaml.Node
|
||||||
|
if err := yaml.Unmarshal(yml, &data); err != nil {
|
||||||
|
return nil, fmt.Errorf("yaml: unmarshal err: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return create(opts...).With(&data), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func create(opts ...Option) *Provider {
|
||||||
|
prov := Provider{
|
||||||
|
key: keyFactory,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(&prov)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &prov
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*Provider)
|
||||||
|
|
||||||
|
type Provider struct {
|
||||||
|
data node
|
||||||
|
key func(context.Context, config.Key) []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Name() string {
|
||||||
|
return "yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
k := p.key(ctx, key)
|
||||||
|
|
||||||
|
return p.data.read(p.Name(), k)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Provider) With(data *yaml.Node) *Provider {
|
||||||
|
return &Provider{
|
||||||
|
key: p.key,
|
||||||
|
data: node{Node: data},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type node struct {
|
||||||
|
*yaml.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *node) read(name string, keys []string) (config.Variable, error) {
|
||||||
|
val, err := getData(n.Node.Content[0].Content, keys)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, config.ErrVariableNotFound) {
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: %s", config.ErrVariableNotFound, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{}, fmt.Errorf("%w: %s", err, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.Variable{
|
||||||
|
Name: strings.Join(keys, "."),
|
||||||
|
Provider: name,
|
||||||
|
Value: value.Decode(val),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getData(node []*yaml.Node, keys []string) (func(interface{}) error, error) {
|
||||||
|
for idx := len(node) - 1; idx > 0; idx -= 2 {
|
||||||
|
if node[idx-1].Value == keys[0] {
|
||||||
|
if len(keys) > 1 {
|
||||||
|
return getData(node[idx].Content, keys[1:])
|
||||||
|
}
|
||||||
|
|
||||||
|
return node[idx].Decode, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, config.ErrVariableNotFound
|
||||||
|
}
|
||||||
26
provider/yaml/provider_test.go
Normal file
26
provider/yaml/provider_test.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package yaml_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
provider "gitoa.ru/go-4devs/config/provider/yaml"
|
||||||
|
"gitoa.ru/go-4devs/config/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProvider(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
prov, err := provider.New(test.ReadFile("config.yaml"))
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
read := []test.Read{
|
||||||
|
test.NewRead("duration_var", 21*time.Minute),
|
||||||
|
test.NewRead("app/name/bool_var", true),
|
||||||
|
test.NewRead("time_var", test.Time("2020-01-02T15:04:05Z")),
|
||||||
|
test.NewReadConfig("cfg"),
|
||||||
|
}
|
||||||
|
|
||||||
|
test.Run(t, prov, read)
|
||||||
|
}
|
||||||
42
provider/yaml/watch.go
Normal file
42
provider/yaml/watch.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package yaml
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"gitoa.ru/go-4devs/config"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewWatch(name string, opts ...Option) *Watch {
|
||||||
|
f := Watch{
|
||||||
|
file: name,
|
||||||
|
prov: create(opts...),
|
||||||
|
}
|
||||||
|
|
||||||
|
return &f
|
||||||
|
}
|
||||||
|
|
||||||
|
type Watch struct {
|
||||||
|
file string
|
||||||
|
prov *Provider
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Watch) Name() string {
|
||||||
|
return "yaml_watch"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Watch) Read(ctx context.Context, key config.Key) (config.Variable, error) {
|
||||||
|
in, err := ioutil.ReadFile(p.file)
|
||||||
|
if err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("yaml_file: read error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var yNode yaml.Node
|
||||||
|
if err = yaml.Unmarshal(in, &yNode); err != nil {
|
||||||
|
return config.Variable{}, fmt.Errorf("yaml_file: unmarshal error: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.prov.With(&yNode).Read(ctx, key)
|
||||||
|
}
|
||||||
46
test/etcd.go
Normal file
46
test/etcd.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
client "go.etcd.io/etcd/client/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewEtcd(ctx context.Context) (*client.Client, error) {
|
||||||
|
dsn, ok := os.LookupEnv("FDEVS_CONFIG_ETCD_HOST")
|
||||||
|
if !ok {
|
||||||
|
dsn = "127.0.0.1:2379"
|
||||||
|
}
|
||||||
|
|
||||||
|
et, err := client.New(client.Config{
|
||||||
|
Endpoints: []string{dsn},
|
||||||
|
DialTimeout: time.Second,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
values := map[string]string{
|
||||||
|
"fdevs/config/db_dsn": "pgsql://user@pass:127.0.0.1:5432",
|
||||||
|
"fdevs/config/duration": "12m",
|
||||||
|
"fdevs/config/port": "8080",
|
||||||
|
"fdevs/config/maintain": "true",
|
||||||
|
"fdevs/config/start_at": "2020-01-02T15:04:05Z",
|
||||||
|
"fdevs/config/percent": "0.064",
|
||||||
|
"fdevs/config/count": "2020",
|
||||||
|
"fdevs/config/int64": "2021",
|
||||||
|
"fdevs/config/uint64": "2022",
|
||||||
|
"fdevs/config/config": ConfigJSON,
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, val := range values {
|
||||||
|
_, err = et.KV.Put(ctx, name, val)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return et, nil
|
||||||
|
}
|
||||||
1038
test/fixture/config.ini
Normal file
1038
test/fixture/config.ini
Normal file
File diff suppressed because it is too large
Load Diff
17
test/fixture/config.json
Normal file
17
test/fixture/config.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"name": {
|
||||||
|
"var": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"title": "config title",
|
||||||
|
"timeout": "1m",
|
||||||
|
"success": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cfg": {
|
||||||
|
"duration": 1260000000000,
|
||||||
|
"enabled": true,
|
||||||
|
"type":"json"
|
||||||
|
}
|
||||||
|
}
|
||||||
31
test/fixture/config.toml
Normal file
31
test/fixture/config.toml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
title = "TOML Example"
|
||||||
|
|
||||||
|
[owner]
|
||||||
|
name = "Tom Preston-Werner"
|
||||||
|
dob = 1979-05-27T07:32:00-08:00 # First class dates
|
||||||
|
|
||||||
|
[database]
|
||||||
|
server = "192.168.1.1"
|
||||||
|
ports = [ 8001, 8001, 8002 ]
|
||||||
|
connection_max = 5000
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[servers]
|
||||||
|
|
||||||
|
# Indentation (tabs and/or spaces) is allowed but not required
|
||||||
|
[servers.alpha]
|
||||||
|
ip = "10.0.0.1"
|
||||||
|
dc = "eqdc10"
|
||||||
|
|
||||||
|
[servers.beta]
|
||||||
|
ip = "10.0.0.2"
|
||||||
|
dc = "eqdc10"
|
||||||
|
|
||||||
|
[clients]
|
||||||
|
data = [ ["gamma", "delta"], [1, 2] ]
|
||||||
|
|
||||||
|
# Line breaks are OK when inside arrays
|
||||||
|
hosts = [
|
||||||
|
"alpha",
|
||||||
|
"omega"
|
||||||
|
]
|
||||||
14
test/fixture/config.yaml
Normal file
14
test/fixture/config.yaml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
app:
|
||||||
|
title: yaml title
|
||||||
|
name:
|
||||||
|
var:
|
||||||
|
- test
|
||||||
|
bool_var: true
|
||||||
|
duration_var: 21m
|
||||||
|
empty_var:
|
||||||
|
url_var: "http://google.com/"
|
||||||
|
time_var: "2020-01-02T15:04:05Z"
|
||||||
|
cfg:
|
||||||
|
duration: 21m
|
||||||
|
enabled: true
|
||||||
|
type: yaml
|
||||||
17
test/helpers.go
Normal file
17
test/helpers.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FixturePath(file string) string {
|
||||||
|
path := "fixture/"
|
||||||
|
|
||||||
|
_, filename, _, ok := runtime.Caller(0)
|
||||||
|
if ok {
|
||||||
|
path = filepath.Dir(filename) + "/" + path
|
||||||
|
}
|
||||||
|
|
||||||
|
return path + file
|
||||||
|
}
|
||||||
16
test/ini.go
Normal file
16
test/ini.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewINI() *ini.File {
|
||||||
|
f, err := ini.Load(FixturePath("config.ini"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f
|
||||||
|
}
|
||||||
15
test/json.go
Normal file
15
test/json.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ReadFile(file string) []byte {
|
||||||
|
data, err := ioutil.ReadFile(FixturePath(file))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
@@ -2,12 +2,14 @@ package test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
"gitoa.ru/go-4devs/config/test/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -19,39 +21,47 @@ const (
|
|||||||
func Run(t *testing.T, provider config.Provider, read []Read) {
|
func Run(t *testing.T, provider config.Provider, read []Read) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
ctx := context.Background()
|
prov := &ProviderSuite{
|
||||||
|
provider: provider,
|
||||||
for idx, read := range read {
|
read: read,
|
||||||
t.Run(fmt.Sprintf("%v:%v", idx, read.Key), func(t *testing.T) {
|
|
||||||
val, err := provider.Value(ctx, read.Key...)
|
|
||||||
require.NoError(t, err, read.Key)
|
|
||||||
read.Assert(t, val)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
suite.Run(t, prov)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProviderSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
provider config.Provider
|
||||||
|
read []Read
|
||||||
}
|
}
|
||||||
|
|
||||||
type Read struct {
|
type Read struct {
|
||||||
Key []string
|
Key config.Key
|
||||||
Assert func(t *testing.T, v config.Value)
|
Assert func(t *testing.T, v config.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ConfigJSON = `{"duration":1260000000000,"enabled":true}`
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
Enabled bool
|
Enabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReadConfig(key ...string) Read {
|
func NewReadConfig(key string) Read {
|
||||||
ex := &Config{
|
ex := &Config{
|
||||||
Duration: 21 * time.Minute,
|
Duration: 21 * time.Minute,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewReadUnmarshal(ex, &Config{}, key...)
|
return NewReadUnmarshal(key, ex, &Config{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReadUnmarshal(expected, target interface{}, key ...string) Read {
|
func NewReadUnmarshal(key string, expected, target interface{}) Read {
|
||||||
return Read{
|
return Read{
|
||||||
Key: key,
|
Key: config.Key{
|
||||||
|
Namespace: "fdevs",
|
||||||
|
AppName: "config",
|
||||||
|
Name: key,
|
||||||
|
},
|
||||||
Assert: func(t *testing.T, v config.Value) {
|
Assert: func(t *testing.T, v config.Value) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
require.NoErrorf(t, v.Unmarshal(target), "unmarshal")
|
require.NoErrorf(t, v.Unmarshal(target), "unmarshal")
|
||||||
@@ -67,9 +77,13 @@ func Time(value string) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// nolint: cyclop
|
// nolint: cyclop
|
||||||
func NewRead(expected interface{}, key ...string) Read {
|
func NewRead(key string, expected interface{}) Read {
|
||||||
return Read{
|
return Read{
|
||||||
Key: key,
|
Key: config.Key{
|
||||||
|
Namespace: "fdevs",
|
||||||
|
AppName: "config",
|
||||||
|
Name: key,
|
||||||
|
},
|
||||||
Assert: func(t *testing.T, v config.Value) {
|
Assert: func(t *testing.T, v config.Value) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
var (
|
var (
|
||||||
@@ -106,7 +120,7 @@ func NewRead(expected interface{}, key ...string) Read {
|
|||||||
val, err = v.ParseTime()
|
val, err = v.ParseTime()
|
||||||
short = v.Time()
|
short = v.Time()
|
||||||
default:
|
default:
|
||||||
require.Fail(t, "unexpected type:%+T", expected)
|
require.Fail(t, "unexpected type", "type:%+T", expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equalf(t, val, short, "type:%T", expected)
|
require.Equalf(t, val, short, "type:%T", expected)
|
||||||
@@ -115,3 +129,22 @@ func NewRead(expected interface{}, key ...string) Read {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ps *ProviderSuite) TestReadKeys() {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
for _, read := range ps.read {
|
||||||
|
val, err := ps.provider.Read(ctx, read.Key)
|
||||||
|
require.NoError(ps.T(), err, read.Key.String())
|
||||||
|
read.Assert(ps.T(), val.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadConfig(t *testing.T, path string) []byte {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
file, err := ioutil.ReadFile(filepath.Clean(path))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package require
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Equal(t *testing.T, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
if reflect.DeepEqual(expected, actual) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Error(msgAndArgs...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Equalf(t *testing.T, expected interface{}, actual interface{}, msg string, args ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
if reflect.DeepEqual(expected, actual) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Errorf(msg, args...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package require
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NoError(t *testing.T, err error, msgAndArgs ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Error(msgAndArgs...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NoErrorf(t *testing.T, err error, msg string, args ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf(msg, args...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package require
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func Fail(t *testing.T, msg string, args ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
t.Errorf(msg, args...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package require
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Truef(t *testing.T, value bool, msg string, args ...interface{}) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
if !value {
|
|
||||||
t.Errorf(msg, args...)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
89
test/vault.go
Normal file
89
test/vault.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/hashicorp/vault/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
const token = "dev"
|
||||||
|
|
||||||
|
func NewVault() (*api.Client, error) {
|
||||||
|
address, ok := os.LookupEnv("VAULT_DEV_LISTEN_ADDRESS")
|
||||||
|
if !ok {
|
||||||
|
address = "http://127.0.0.1:8200"
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenID, ok := os.LookupEnv("VAULT_DEV_ROOT_TOKEN_ID")
|
||||||
|
if !ok {
|
||||||
|
tokenID = token
|
||||||
|
}
|
||||||
|
|
||||||
|
cl, err := api.NewClient(&api.Config{
|
||||||
|
Address: address,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cl.SetToken(tokenID)
|
||||||
|
|
||||||
|
values := map[string]map[string]interface{}{
|
||||||
|
"database": {
|
||||||
|
"duration": 1260000000000,
|
||||||
|
"enabled": true,
|
||||||
|
},
|
||||||
|
"db": {
|
||||||
|
"dsn": DSN,
|
||||||
|
"timeout": "60s",
|
||||||
|
},
|
||||||
|
"example": {
|
||||||
|
"dsn": DSN,
|
||||||
|
"timeout": "60s",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, val := range values {
|
||||||
|
if err := create(address, tokenID, name, val); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cl, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func create(host, token, path string, data map[string]interface{}) error {
|
||||||
|
type Req struct {
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(Req{Data: data})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
body := bytes.NewBuffer(b)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(
|
||||||
|
context.Background(),
|
||||||
|
http.MethodPost,
|
||||||
|
host+"/v1/secret/data/fdevs/config/"+path,
|
||||||
|
body,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("X-Vault-Token", token)
|
||||||
|
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Body.Close()
|
||||||
|
}
|
||||||
1
value.go
1
value.go
@@ -8,7 +8,6 @@ type Value interface {
|
|||||||
ReadValue
|
ReadValue
|
||||||
ParseValue
|
ParseValue
|
||||||
UnmarshalValue
|
UnmarshalValue
|
||||||
IsEquals(in Value) bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UnmarshalValue interface {
|
type UnmarshalValue interface {
|
||||||
|
|||||||
@@ -108,7 +108,3 @@ func (s Decode) Time() time.Time {
|
|||||||
|
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Decode) IsEquals(in config.Value) bool {
|
|
||||||
return s.String() == in.String()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -110,7 +110,3 @@ func (s JBytes) Time() time.Time {
|
|||||||
|
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s JBytes) IsEquals(in config.Value) bool {
|
|
||||||
return s.String() == in.String()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -110,7 +110,3 @@ func (s JString) Time() time.Time {
|
|||||||
|
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s JString) IsEquals(in config.Value) bool {
|
|
||||||
return s.String() == in.String()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"gitoa.ru/go-4devs/config"
|
"gitoa.ru/go-4devs/config"
|
||||||
"gitoa.ru/go-4devs/config/test/require"
|
|
||||||
"gitoa.ru/go-4devs/config/value"
|
"gitoa.ru/go-4devs/config/value"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,3 @@ func (s Value) ParseTime() (time.Time, error) {
|
|||||||
|
|
||||||
return time.Time{}, config.ErrInvalidValue
|
return time.Time{}, config.ErrInvalidValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Value) IsEquals(in config.Value) bool {
|
|
||||||
return s.String() == in.String()
|
|
||||||
}
|
|
||||||
|
|||||||
11
variable.go
Normal file
11
variable.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
type Variable struct {
|
||||||
|
Name string
|
||||||
|
Provider string
|
||||||
|
Value Value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v Variable) IsEquals(n Variable) bool {
|
||||||
|
return n.Name == v.Name && n.Provider == v.Provider && n.Value.String() == v.Value.String()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user