andrey1s
4 years ago
commit
913ca9672d
55 changed files with 4355 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||
|
kind: pipeline |
||||
|
name: default |
||||
|
|
||||
|
services: |
||||
|
- name: vault |
||||
|
image: vault |
||||
|
environment: |
||||
|
VAULT_DEV_ROOT_TOKEN_ID: dev |
||||
|
- name: etcd |
||||
|
image: bitnami/etcd |
||||
|
|
||||
|
environment: |
||||
|
VAULT_DEV_LISTEN_ADDRESS: vault:8200 |
||||
|
VAULT_DEV_ROOT_TOKEN_ID: dev |
||||
|
FDEVS_CONFIG_ETCD_HOST: etcd:2379 |
||||
|
|
||||
|
steps: |
||||
|
- name: test |
||||
|
image: golang |
||||
|
commands: |
||||
|
- go test -parallel 10 -race ./... |
||||
|
|
||||
|
- name: golangci-lint |
||||
|
image: golangci/golangci-lint:v1.39 |
||||
|
commands: |
||||
|
- golangci-lint run |
@ -0,0 +1,17 @@ |
|||||
|
# ---> Go |
||||
|
# Binaries for programs and plugins |
||||
|
*.exe |
||||
|
*.exe~ |
||||
|
*.dll |
||||
|
*.so |
||||
|
*.dylib |
||||
|
|
||||
|
# Test binary, built with `go test -c` |
||||
|
*.test |
||||
|
|
||||
|
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
|
*.out |
||||
|
|
||||
|
# Dependency directories (remove the comment below to include it) |
||||
|
# vendor/ |
||||
|
|
@ -0,0 +1,46 @@ |
|||||
|
run: |
||||
|
timeout: 5m |
||||
|
|
||||
|
linters-settings: |
||||
|
dupl: |
||||
|
threshold: 100 |
||||
|
funlen: |
||||
|
lines: 100 |
||||
|
statements: 50 |
||||
|
goconst: |
||||
|
min-len: 2 |
||||
|
min-occurrences: 2 |
||||
|
gocyclo: |
||||
|
min-complexity: 15 |
||||
|
golint: |
||||
|
min-confidence: 0 |
||||
|
govet: |
||||
|
check-shadowing: true |
||||
|
lll: |
||||
|
line-length: 140 |
||||
|
maligned: |
||||
|
suggest-new: true |
||||
|
misspell: |
||||
|
locale: US |
||||
|
|
||||
|
linters: |
||||
|
enable-all: true |
||||
|
disable: |
||||
|
- exhaustivestruct |
||||
|
- maligned |
||||
|
- interfacer |
||||
|
- scopelint |
||||
|
|
||||
|
issues: |
||||
|
# Excluding configuration per-path, per-linter, per-text and per-source |
||||
|
exclude-rules: |
||||
|
- path: _test\.go |
||||
|
linters: |
||||
|
- gomnd |
||||
|
- exhaustivestruct |
||||
|
- wrapcheck |
||||
|
- path: test/* |
||||
|
linters: |
||||
|
- gomnd |
||||
|
- exhaustivestruct |
||||
|
- wrapcheck |
@ -0,0 +1,19 @@ |
|||||
|
MIT License Copyright (c) 2020 4devs |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is furnished |
||||
|
to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice (including the next |
||||
|
paragraph) shall be included in all copies or substantial portions of the |
||||
|
Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS |
||||
|
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF |
||||
|
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,5 @@ |
|||||
|
# config |
||||
|
|
||||
|
[![Build Status](https://drone.gitoa.ru/api/badges/go-4devs/cache/status.svg)](https://drone.gitoa.ru/go-4devs/config) |
||||
|
[![Go Report Card](https://goreportcard.com/badge/gitoa.ru/go-4devs/config)](https://goreportcard.com/report/gitoa.ru/go-4devs/config) |
||||
|
[![GoDoc](https://godoc.org/gitoa.ru/go-4devs/config?status.svg)](http://godoc.org/gitoa.ru/go-4devs/config) |
@ -0,0 +1,96 @@ |
|||||
|
package config |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
) |
||||
|
|
||||
|
func New(namespace, appName string, providers []Provider) *Client { |
||||
|
return &Client{ |
||||
|
namespace: namespace, |
||||
|
appName: appName, |
||||
|
providers: providers, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
type Client struct { |
||||
|
providers []Provider |
||||
|
appName string |
||||
|
namespace string |
||||
|
} |
||||
|
|
||||
|
func (c *Client) key(name string) Key { |
||||
|
return Key{ |
||||
|
Name: name, |
||||
|
AppName: c.appName, |
||||
|
Namespace: c.namespace, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (c *Client) Value(ctx context.Context, name string) (Value, error) { |
||||
|
variable, err := c.Variable(ctx, name) |
||||
|
if err != nil { |
||||
|
return nil, err |
||||
|
} |
||||
|
|
||||
|
return variable.Value, nil |
||||
|
} |
||||
|
|
||||
|
func (c *Client) Variable(ctx context.Context, name string) (Variable, error) { |
||||
|
var ( |
||||
|
variable Variable |
||||
|
err error |
||||
|
) |
||||
|
|
||||
|
key := c.key(name) |
||||
|
|
||||
|
for _, provider := range c.providers { |
||||
|
variable, err = provider.Read(ctx, key) |
||||
|
if err == nil || !errors.Is(err, ErrVariableNotFound) { |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if err != nil { |
||||
|
return variable, fmt.Errorf("client failed get variable: %w", err) |
||||
|
} |
||||
|
|
||||
|
return variable, nil |
||||
|
} |
||||
|
|
||||
|
func NewWatch(namespace, appName string, providers []Provider) *WatchClient { |
||||
|
cl := WatchClient{ |
||||
|
Client: New(namespace, appName, providers), |
||||
|
} |
||||
|
|
||||
|
for _, provider := range providers { |
||||
|
if watch, ok := provider.(WatchProvider); ok { |
||||
|
cl.providers = append(cl.providers, watch) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return &cl |
||||
|
} |
||||
|
|
||||
|
type WatchClient struct { |
||||
|
*Client |
||||
|
providers []WatchProvider |
||||
|
} |
||||
|
|
||||
|
func (wc *WatchClient) Watch(ctx context.Context, name string, callback WatchCallback) error { |
||||
|
key := wc.key(name) |
||||
|
|
||||
|
for _, provider := range wc.providers { |
||||
|
err := provider.Watch(ctx, key, callback) |
||||
|
if err != nil { |
||||
|
if errors.Is(err, ErrVariableNotFound) { |
||||
|
continue |
||||
|
} |
||||
|
|
||||
|
return fmt.Errorf("client: failed watch by provider %s: %w", provider.Name(), err) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
@ -0,0 +1,198 @@ |
|||||
|
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 ExampleNew() { |
||||
|
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") |
||||
|
|
||||
|
providers := []config.Provider{ |
||||
|
arg.New(), |
||||
|
env.New(), |
||||
|
etcd.NewProvider(etcdClient), |
||||
|
vault.NewSecretKV2(vaultClient), |
||||
|
json.New(jsonConfig), |
||||
|
} |
||||
|
config := config.New(test.Namespace, test.AppName, providers) |
||||
|
|
||||
|
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 ExampleNewWatch() { |
||||
|
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 |
||||
|
} |
||||
|
}() |
||||
|
|
||||
|
providers := []config.Provider{ |
||||
|
watcher.New(time.Microsecond, env.New()), |
||||
|
watcher.New(time.Microsecond, yaml.NewFile("test/fixture/config.yaml")), |
||||
|
etcd.NewProvider(etcdClient), |
||||
|
} |
||||
|
watcher := config.NewWatch(test.Namespace, test.AppName, providers) |
||||
|
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
|
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
version: '3' |
||||
|
|
||||
|
services: |
||||
|
vault: |
||||
|
image: vault:latest |
||||
|
cap_add: |
||||
|
- IPC_LOCK |
||||
|
ports: |
||||
|
- "8200:8200" |
||||
|
environment: |
||||
|
VAULT_DEV_ROOT_TOKEN_ID: "dev" |
||||
|
etcd: |
||||
|
image: bitnami/etcd |
||||
|
environment: |
||||
|
ALLOW_NONE_AUTHENTICATION: "yes" |
||||
|
ports: |
||||
|
- "2379:2379" |
@ -0,0 +1,8 @@ |
|||||
|
package config |
||||
|
|
||||
|
import "errors" |
||||
|
|
||||
|
var ( |
||||
|
ErrVariableNotFound = errors.New("variable not found") |
||||
|
ErrInvalidValue = errors.New("invalid value") |
||||
|
) |
@ -0,0 +1,15 @@ |
|||||
|
module gitoa.ru/go-4devs/config |
||||
|
|
||||
|
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 |
||||
|
) |
@ -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= |
@ -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 |
||||
|
} |
@ -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) { |
||||
|
k := factory(ctx, key) |
||||
|
|
||||
|
idx := strings.LastIndex(k, sep) |
||||
|
if idx == -1 { |
||||
|
return k, "" |
||||
|
} |
||||
|
|
||||
|
return k[0:idx], k[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 |
||||
|
} |
||||
|
} |
@ -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) |
||||
|
} |
||||
|
} |
@ -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) |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package config |
||||
|
|
||||
|
import "context" |
||||
|
|
||||
|
type Provider interface { |
||||
|
Read(ctx context.Context, key Key) (Variable, error) |
||||
|
NamedProvider |
||||
|
} |
||||
|
|
||||
|
type WatchCallback func(ctx context.Context, oldVar, newVar Variable) |
||||
|
|
||||
|
type WatchProvider interface { |
||||
|
Watch(ctx context.Context, key Key, callback WatchCallback) error |
||||
|
NamedProvider |
||||
|
} |
||||
|
|
||||
|
type NamedProvider interface { |
||||
|
Name() string |
||||
|
} |
@ -0,0 +1,136 @@ |
|||||
|
package arg |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"os" |
||||
|
"strings" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gitoa.ru/go-4devs/config/key" |
||||
|
"gitoa.ru/go-4devs/config/value" |
||||
|
"gopkg.in/yaml.v3" |
||||
|
) |
||||
|
|
||||
|
var _ config.Provider = (*Provider)(nil) |
||||
|
|
||||
|
type Option func(*Provider) |
||||
|
|
||||
|
func WithKeyFactory(factory config.KeyFactory) Option { |
||||
|
return func(p *Provider) { p.key = factory } |
||||
|
} |
||||
|
|
||||
|
func New(opts ...Option) *Provider { |
||||
|
p := Provider{ |
||||
|
key: key.Name, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(&p) |
||||
|
} |
||||
|
|
||||
|
return &p |
||||
|
} |
||||
|
|
||||
|
type Provider struct { |
||||
|
args map[string][]string |
||||
|
key config.KeyFactory |
||||
|
} |
||||
|
|
||||
|
// nolint: cyclop
|
||||
|
func (p *Provider) parseOne(arg string) (name, val string, err error) { |
||||
|
if arg[0] != '-' { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
numMinuses := 1 |
||||
|
|
||||
|
if arg[1] == '-' { |
||||
|
numMinuses++ |
||||
|
} |
||||
|
|
||||
|
name = strings.TrimSpace(arg[numMinuses:]) |
||||
|
if len(name) == 0 { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
if name[0] == '-' || name[0] == '=' { |
||||
|
return "", "", fmt.Errorf("%w: bad flag syntax: %s", config.ErrInvalidValue, arg) |
||||
|
} |
||||
|
|
||||
|
for i := 1; i < len(name); i++ { |
||||
|
if name[i] == '=' || name[i] == ' ' { |
||||
|
val = strings.TrimSpace(name[i+1:]) |
||||
|
name = name[0:i] |
||||
|
|
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if val == "" && numMinuses == 1 && len(arg) > 2 { |
||||
|
name, val = name[:1], name[1:] |
||||
|
} |
||||
|
|
||||
|
return name, val, nil |
||||
|
} |
||||
|
|
||||
|
func (p *Provider) parse() error { |
||||
|
if len(p.args) > 0 { |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
p.args = make(map[string][]string, len(os.Args[1:])) |
||||
|
|
||||
|
for _, arg := range os.Args[1:] { |
||||
|
name, value, err := p.parseOne(arg) |
||||
|
if err != nil { |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
if name != "" { |
||||
|
p.args[name] = append(p.args[name], value) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
func (p *Provider) Name() string { |
||||
|
return "arg" |
||||
|
} |
||||
|
|
||||
|
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 { |
||||
|
return config.Variable{Provider: p.Name()}, err |
||||
|
} |
||||
|
|
||||
|
k := p.key(ctx, key) |
||||
|
if val, ok := p.args[k]; ok { |
||||
|
switch { |
||||
|
case len(val) == 1: |
||||
|
return config.Variable{ |
||||
|
Name: k, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.JString(val[0]), |
||||
|
}, nil |
||||
|
default: |
||||
|
var n yaml.Node |
||||
|
|
||||
|
if err := yaml.Unmarshal([]byte("["+strings.Join(val, ",")+"]"), &n); err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("arg: failed unmarshal yaml:%w", err) |
||||
|
} |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: k, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.Decode(n.Decode), |
||||
|
}, nil |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return config.Variable{Name: k, Provider: p.Name()}, config.ErrVariableNotFound |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
package arg_test |
||||
|
|
||||
|
import ( |
||||
|
"os" |
||||
|
"testing" |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config/provider/arg" |
||||
|
"gitoa.ru/go-4devs/config/test" |
||||
|
) |
||||
|
|
||||
|
func TestProvider(t *testing.T) { |
||||
|
t.Parallel() |
||||
|
|
||||
|
args := os.Args |
||||
|
|
||||
|
defer func() { |
||||
|
os.Args = args |
||||
|
}() |
||||
|
|
||||
|
os.Args = []string{ |
||||
|
"main.go", |
||||
|
"--listen=8080", |
||||
|
"--config=config.hcl", |
||||
|
"--url=http://4devs.io", |
||||
|
"--url=https://4devs.io", |
||||
|
"--timeout=1m", |
||||
|
"--timeout=1h", |
||||
|
"--start-at=2010-01-02T15:04:05Z", |
||||
|
"--end-after=2009-01-02T15:04:05Z", |
||||
|
"--end-after=2008-01-02T15:04:05+03:00", |
||||
|
} |
||||
|
read := []test.Read{ |
||||
|
test.NewRead("listen", 8080), |
||||
|
test.NewRead("config", "config.hcl"), |
||||
|
test.NewRead("start-at", test.Time("2010-01-02T15:04:05Z")), |
||||
|
test.NewReadUnmarshal("url", &[]string{"http://4devs.io", "https://4devs.io"}, &[]string{}), |
||||
|
test.NewReadUnmarshal("timeout", &[]time.Duration{time.Minute, time.Hour}, &[]time.Duration{}), |
||||
|
test.NewReadUnmarshal("end-after", &[]time.Time{ |
||||
|
test.Time("2009-01-02T15:04:05Z"), |
||||
|
test.Time("2008-01-02T15:04:05+03:00"), |
||||
|
}, &[]time.Time{}), |
||||
|
} |
||||
|
|
||||
|
prov := arg.New() |
||||
|
|
||||
|
test.Run(t, prov, read) |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
package env |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"os" |
||||
|
"strings" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gitoa.ru/go-4devs/config/key" |
||||
|
"gitoa.ru/go-4devs/config/value" |
||||
|
) |
||||
|
|
||||
|
var _ config.Provider = (*Provider)(nil) |
||||
|
|
||||
|
type Option func(*Provider) |
||||
|
|
||||
|
func WithKeyFactory(factory config.KeyFactory) Option { |
||||
|
return func(p *Provider) { p.key = factory } |
||||
|
} |
||||
|
|
||||
|
func New(opts ...Option) *Provider { |
||||
|
p := Provider{ |
||||
|
key: func(ctx context.Context, k config.Key) string { |
||||
|
return strings.ToUpper(key.NsAppName("_")(ctx, k)) |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(&p) |
||||
|
} |
||||
|
|
||||
|
return &p |
||||
|
} |
||||
|
|
||||
|
type Provider struct { |
||||
|
key config.KeyFactory |
||||
|
} |
||||
|
|
||||
|
func (p *Provider) Name() string { |
||||
|
return "env" |
||||
|
} |
||||
|
|
||||
|
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) { |
||||
|
k := p.key(ctx, key) |
||||
|
if val, ok := os.LookupEnv(k); ok { |
||||
|
return config.Variable{ |
||||
|
Name: k, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.JString(val), |
||||
|
}, nil |
||||
|
} |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: k, |
||||
|
Provider: p.Name(), |
||||
|
}, config.ErrVariableNotFound |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package env_test |
||||
|
|
||||
|
import ( |
||||
|
"os" |
||||
|
"testing" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config/provider/env" |
||||
|
"gitoa.ru/go-4devs/config/test" |
||||
|
) |
||||
|
|
||||
|
func TestProvider(t *testing.T) { |
||||
|
t.Parallel() |
||||
|
|
||||
|
os.Setenv("FDEVS_CONFIG_DSN", test.DSN) |
||||
|
os.Setenv("FDEVS_CONFIG_PORT", "8080") |
||||
|
|
||||
|
provider := env.New() |
||||
|
|
||||
|
read := []test.Read{ |
||||
|
test.NewRead("dsn", test.DSN), |
||||
|
test.NewRead("port", 8080), |
||||
|
} |
||||
|
test.Run(t, provider, read) |
||||
|
} |
@ -0,0 +1,113 @@ |
|||||
|
package etcd |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"log" |
||||
|
|
||||
|
"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) { |
||||
|
k := p.key(ctx, key) |
||||
|
|
||||
|
resp, err := p.client.Get(ctx, k, client.WithPrefix()) |
||||
|
if err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("%w: key:%s, prov:%s", err, k, p.Name()) |
||||
|
} |
||||
|
|
||||
|
val, err := p.resolve(k, resp.Kvs) |
||||
|
if err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("%w: key:%s, prov:%s", err, k, 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) |
||||
|
log.Println(events[i].Type) |
||||
|
} |
||||
|
|
||||
|
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(), |
||||
|
}, nil |
||||
|
case string(kv.Key) == key: |
||||
|
return config.Variable{ |
||||
|
Value: value.JBytes(kv.Value), |
||||
|
Name: key, |
||||
|
Provider: p.Name(), |
||||
|
}, nil |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: key, |
||||
|
Provider: p.Name(), |
||||
|
}, config.ErrVariableNotFound |
||||
|
} |
@ -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() |
||||
|
} |
@ -0,0 +1,62 @@ |
|||||
|
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 { |
||||
|
return &Provider{ |
||||
|
data: data, |
||||
|
resolve: func(ctx context.Context, key config.Key) (string, string) { |
||||
|
keys := strings.SplitN(key.Name, "/", 2) |
||||
|
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: %v", config.ErrVariableNotFound, p.Name(), err) |
||||
|
} |
||||
|
|
||||
|
iniKey, err := iniSection.GetKey(name) |
||||
|
if err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("%w: %s: %v", config.ErrVariableNotFound, p.Name(), err) |
||||
|
} |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: section + ":" + name, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.JString(iniKey.String()), |
||||
|
}, nil |
||||
|
} |
@ -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) |
||||
|
} |
@ -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), 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 |
||||
|
} |
@ -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) |
||||
|
} |
@ -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 { |
||||
|
p := &Provider{ |
||||
|
tree: tree, |
||||
|
key: key.Name, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(p) |
||||
|
} |
||||
|
|
||||
|
return p |
||||
|
} |
||||
|
|
||||
|
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 |
||||
|
} |
@ -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) |
||||
|
} |
@ -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: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
if err := json.Unmarshal(b, target); err != nil { |
||||
|
return fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
@ -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 { |
||||
|
s := SecretKV2{ |
||||
|
client: client, |
||||
|
resolve: key.LastIndexField(":", "value", key.PrefixName("secret/data/", key.NsAppName("/"))), |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(&s) |
||||
|
} |
||||
|
|
||||
|
return &s |
||||
|
} |
||||
|
|
||||
|
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) |
||||
|
|
||||
|
s, 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 s == nil || len(s.Data) == 0 { |
||||
|
return config.Variable{}, fmt.Errorf("%w: path:%s, field:%s, provider:%s", config.ErrVariableNotFound, path, field, p.Name()) |
||||
|
} |
||||
|
|
||||
|
if len(s.Warnings) > 0 { |
||||
|
return config.Variable{}, |
||||
|
fmt.Errorf("%w: warn: %s, path:%s, field:%s, provider:%s", config.ErrVariableNotFound, s.Warnings, path, field, p.Name()) |
||||
|
} |
||||
|
|
||||
|
d, ok := s.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 := d[field]; ok { |
||||
|
return config.Variable{ |
||||
|
Name: path + field, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.JString(fmt.Sprint(val)), |
||||
|
}, nil |
||||
|
} |
||||
|
|
||||
|
md, err := json.Marshal(d) |
||||
|
if err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: path + field, |
||||
|
Provider: p.Name(), |
||||
|
Value: value.JBytes(md), |
||||
|
}, nil |
||||
|
} |
@ -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) |
||||
|
} |
@ -0,0 +1,71 @@ |
|||||
|
package watcher |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"log" |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
var ( |
||||
|
_ config.Provider = (*Provider)(nil) |
||||
|
_ config.WatchProvider = (*Provider)(nil) |
||||
|
) |
||||
|
|
||||
|
func New(duration time.Duration, provider config.Provider, opts ...Option) *Provider { |
||||
|
p := &Provider{ |
||||
|
Provider: provider, |
||||
|
ticker: time.NewTicker(duration), |
||||
|
logger: func(_ context.Context, msg string) { |
||||
|
log.Print(msg) |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(p) |
||||
|
} |
||||
|
|
||||
|
return p |
||||
|
} |
||||
|
|
||||
|
func WithLogger(l func(context.Context, string)) Option { |
||||
|
return func(p *Provider) { |
||||
|
p.logger = l |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
type Option func(*Provider) |
||||
|
|
||||
|
type Provider struct { |
||||
|
config.Provider |
||||
|
ticker *time.Ticker |
||||
|
logger func(context.Context, string) |
||||
|
} |
||||
|
|
||||
|
func (p *Provider) Watch(ctx context.Context, key config.Key, callback config.WatchCallback) error { |
||||
|
oldVar, err := p.Provider.Read(ctx, key) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("%s: failed watch variable: %w", p.Provider.Name(), err) |
||||
|
} |
||||
|
|
||||
|
go func() { |
||||
|
for { |
||||
|
select { |
||||
|
case <-p.ticker.C: |
||||
|
newVar, err := p.Provider.Read(ctx, key) |
||||
|
if err != nil { |
||||
|
p.logger(ctx, err.Error()) |
||||
|
} else if !newVar.IsEquals(oldVar) { |
||||
|
callback(ctx, oldVar, newVar) |
||||
|
oldVar = newVar |
||||
|
} |
||||
|
case <-ctx.Done(): |
||||
|
return |
||||
|
} |
||||
|
} |
||||
|
}() |
||||
|
|
||||
|
return nil |
||||
|
} |
@ -0,0 +1,58 @@ |
|||||
|
package watcher_test |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"sync" |
||||
|
"sync/atomic" |
||||
|
"testing" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/stretchr/testify/require" |
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gitoa.ru/go-4devs/config/provider/watcher" |
||||
|
"gitoa.ru/go-4devs/config/value" |
||||
|
) |
||||
|
|
||||
|
type provider struct { |
||||
|
cnt int32 |
||||
|
} |
||||
|
|
||||
|
func (p *provider) Name() string { |
||||
|
return "test" |
||||
|
} |
||||
|
|
||||
|
func (p *provider) Read(ctx context.Context, k config.Key) (config.Variable, error) { |
||||
|
p.cnt++ |
||||
|
|
||||
|
return config.Variable{ |
||||
|
Name: "tmpname", |
||||
|
Value: value.JString(fmt.Sprint(p.cnt)), |
||||
|
}, nil |
||||
|
} |
||||
|
|
||||
|
func TestWatcher(t *testing.T) { |
||||
|
t.Parallel() |
||||
|
|
||||
|
ctx := context.Background() |
||||
|
prov := &provider{} |
||||
|
|
||||
|
w := watcher.New(time.Second, prov) |
||||
|
wg := sync.WaitGroup{} |
||||
|
wg.Add(2) |
||||
|
|
||||
|
var cnt int32 |
||||
|
|
||||
|
err := w.Watch( |
||||
|
ctx, |
||||
|
config.Key{Name: "tmpname"}, |
||||
|
func(ctx context.Context, oldVar, newVar config.Variable) { |
||||
|
atomic.AddInt32(&cnt, 1) |
||||
|
wg.Done() |
||||
|
}, |
||||
|
) |
||||
|
require.NoError(t, err) |
||||
|
wg.Wait() |
||||
|
|
||||
|
require.Equal(t, int32(2), cnt) |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
package yaml |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"io/ioutil" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gopkg.in/yaml.v3" |
||||
|
) |
||||
|
|
||||
|
func WithFileKeyFactory(f func(context.Context, config.Key) []string) FileOption { |
||||
|
return func(p *File) { |
||||
|
p.key = f |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
type FileOption func(*File) |
||||
|
|
||||
|
func NewFile(name string, opts ...FileOption) *File { |
||||
|
f := File{ |
||||
|
file: name, |
||||
|
key: keyFactory, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(&f) |
||||
|
} |
||||
|
|
||||
|
return &f |
||||
|
} |
||||
|
|
||||
|
type File struct { |
||||
|
file string |
||||
|
key func(context.Context, config.Key) []string |
||||
|
} |
||||
|
|
||||
|
func (p *File) Name() string { |
||||
|
return "yaml_file" |
||||
|
} |
||||
|
|
||||
|
func (p *File) 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 n yaml.Node |
||||
|
if err = yaml.Unmarshal(in, &n); err != nil { |
||||
|
return config.Variable{}, fmt.Errorf("yaml_file: unmarshal error: %w", err) |
||||
|
} |
||||
|
|
||||
|
data := node{Node: &n} |
||||
|
k := p.key(ctx, key) |
||||
|
|
||||
|
return data.read(p.Name(), k) |
||||
|
} |
@ -0,0 +1,88 @@ |
|||||
|
package yaml |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"strings" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gitoa.ru/go-4devs/config/value" |
||||
|
"gopkg.in/yaml.v3" |
||||
|
) |
||||
|
|
||||
|
var _ config.Provider = (*Provider)(nil) |
||||
|
|
||||
|
func keyFactory(ctx context.Context, key config.Key) []string { |
||||
|
return strings.Split(key.Name, "/") |
||||
|
} |
||||
|
|
||||
|
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) |
||||
|
} |
||||
|
|
||||
|
p := Provider{ |
||||
|
key: keyFactory, |
||||
|
data: node{Node: &data}, |
||||
|
} |
||||
|
|
||||
|
for _, opt := range opts { |
||||
|
opt(&p) |
||||
|
} |
||||
|
|
||||
|
return &p, nil |
||||
|
} |
||||
|
|
||||
|
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) |
||||
|
} |
||||
|
|
||||
|
type node struct { |
||||
|
*yaml.Node |
||||
|
} |
||||
|
|
||||
|
func (n *node) read(name string, k []string) (config.Variable, error) { |
||||
|
val, err := getData(n.Node.Content[0].Content, k) |
||||
|
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(k, "."), |
||||
|
Provider: name, |
||||
|
Value: value.Decode(val), |
||||
|
}, nil |
||||
|
} |
||||
|
|
||||
|
func getData(node []*yaml.Node, keys []string) (func(interface{}) error, error) { |
||||
|
for i := len(node) - 1; i > 0; i -= 2 { |
||||
|
if node[i-1].Value == keys[0] { |
||||
|
if len(keys) > 1 { |
||||
|
return getData(node[i].Content, keys[1:]) |
||||
|
} |
||||
|
|
||||
|
return node[i].Decode, nil |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return nil, config.ErrVariableNotFound |
||||
|
} |
@ -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) |
||||
|
} |
@ -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 |
||||
|
} |
File diff suppressed because it is too large
@ -0,0 +1,16 @@ |
|||||
|
{ |
||||
|
"app": { |
||||
|
"name": { |
||||
|
"var": [ |
||||
|
"name" |
||||
|
], |
||||
|
"title": "config title", |
||||
|
"timeout": "1m", |
||||
|
"success": true |
||||
|
} |
||||
|
}, |
||||
|
"cfg": { |
||||
|
"duration": 1260000000000, |
||||
|
"enabled": true |
||||
|
} |
||||
|
} |
@ -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" |
||||
|
] |
@ -0,0 +1,12 @@ |
|||||
|
app: |
||||
|
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 |
@ -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 |
||||
|
} |
@ -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 |
||||
|
} |
@ -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 |
||||
|
} |
@ -0,0 +1,150 @@ |
|||||
|
package test |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"io/ioutil" |
||||
|
"path/filepath" |
||||
|
"testing" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/stretchr/testify/require" |
||||
|
"github.com/stretchr/testify/suite" |
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
const ( |
||||
|
DSN = "pgsql://user@pass:127.0.0.1:5432" |
||||
|
Namespace = "fdevs" |
||||
|
AppName = "config" |
||||
|
) |
||||
|
|
||||
|
func Run(t *testing.T, provider config.Provider, read []Read) { |
||||
|
t.Helper() |
||||
|
|
||||
|
prov := &ProviderSuite{ |
||||
|
provider: provider, |
||||
|
read: read, |
||||
|
} |
||||
|
suite.Run(t, prov) |
||||
|
} |
||||
|
|
||||
|
type ProviderSuite struct { |
||||
|
suite.Suite |
||||
|
provider config.Provider |
||||
|
read []Read |
||||
|
} |
||||
|
|
||||
|
type Read struct { |
||||
|
Key config.Key |
||||
|
Assert func(t *testing.T, v config.Value) |
||||
|
} |
||||
|
|
||||
|
const ConfigJSON = `{"duration":1260000000000,"enabled":true}` |
||||
|
|
||||
|
type Config struct { |
||||
|
Duration time.Duration |
||||
|
Enabled bool |
||||
|
} |
||||
|
|
||||
|
func NewReadConfig(key string) Read { |
||||
|
ex := &Config{ |
||||
|
Duration: 21 * time.Minute, |
||||
|
Enabled: true, |
||||
|
} |
||||
|
|
||||
|
return NewReadUnmarshal(key, ex, &Config{}) |
||||
|
} |
||||
|
|
||||
|
func NewReadUnmarshal(key string, expected, target interface{}) Read { |
||||
|
return Read{ |
||||
|
Key: config.Key{ |
||||
|
Namespace: "fdevs", |
||||
|
AppName: "config", |
||||
|
Name: key, |
||||
|
}, |
||||
|
Assert: func(t *testing.T, v config.Value) { |
||||
|
t.Helper() |
||||
|
require.NoErrorf(t, v.Unmarshal(target), "unmarshal") |
||||
|
require.Equal(t, expected, target, "unmarshal") |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func Time(value string) time.Time { |
||||
|
t, _ := time.Parse(time.RFC3339, value) |
||||
|
|
||||
|
return t |
||||
|
} |
||||
|
|
||||
|
// nolint: cyclop
|
||||
|
func NewRead(key string, expected interface{}) Read { |
||||
|
return Read{ |
||||
|
Key: config.Key{ |
||||
|
Namespace: "fdevs", |
||||
|
AppName: "config", |
||||
|
Name: key, |
||||
|
}, |
||||
|
Assert: func(t *testing.T, v config.Value) { |
||||
|
t.Helper() |
||||
|
var ( |
||||
|
val interface{} |
||||
|
err error |
||||
|
short interface{} |
||||
|
) |
||||
|
switch expected.(type) { |
||||
|
case bool: |
||||
|
val, err = v.ParseBool() |
||||
|
short = v.Bool() |
||||
|
case int: |
||||
|
val, err = v.ParseInt() |
||||
|
short = v.Int() |
||||
|
case int64: |
||||
|
val, err = v.ParseInt64() |
||||
|
short = v.Int64() |
||||
|
case uint: |
||||
|
val, err = v.ParseUint() |
||||
|
short = v.Uint() |
||||
|
case uint64: |
||||
|
val, err = v.ParseUint64() |
||||
|
short = v.Uint64() |
||||
|
case string: |
||||
|
val, err = v.ParseString() |
||||
|
short = v.String() |
||||
|
case float64: |
||||
|
val, err = v.ParseFloat64() |
||||
|
short = v.Float64() |
||||
|
case time.Duration: |
||||
|
val, err = v.ParseDuration() |
||||
|
short = v.Duration() |
||||
|
case time.Time: |
||||
|
val, err = v.ParseTime() |
||||
|
short = v.Time() |
||||
|
default: |
||||
|
require.Fail(t, "unexpected type", "type:%+T", expected) |
||||
|
} |
||||
|
|
||||
|
require.Equalf(t, val, short, "type:%T", expected) |
||||
|
require.NoErrorf(t, err, "type:%T", expected) |
||||
|
require.Equalf(t, expected, val, "type:%T", expected) |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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 |
||||
|
} |
@ -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() |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
package config |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
type Value interface { |
||||
|
ReadValue |
||||
|
ParseValue |
||||
|
UnmarshalValue |
||||
|
} |
||||
|
|
||||
|
type UnmarshalValue interface { |
||||
|
Unmarshal(val interface{}) error |
||||
|
} |
||||
|
|
||||
|
type ReadValue interface { |
||||
|
String() string |
||||
|
Int() int |
||||
|
Int64() int64 |
||||
|
Uint() uint |
||||
|
Uint64() uint64 |
||||
|
Float64() float64 |
||||
|
Bool() bool |
||||
|
Duration() time.Duration |
||||
|
Time() time.Time |
||||
|
} |
||||
|
|
||||
|
type ParseValue interface { |
||||
|
ParseString() (string, error) |
||||
|
ParseInt() (int, error) |
||||
|
ParseInt64() (int64, error) |
||||
|
ParseUint() (uint, error) |
||||
|
ParseUint64() (uint64, error) |
||||
|
ParseFloat64() (float64, error) |
||||
|
ParseBool() (bool, error) |
||||
|
ParseDuration() (time.Duration, error) |
||||
|
ParseTime() (time.Time, error) |
||||
|
} |
@ -0,0 +1,109 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
var _ config.Value = (*Decode)(nil) |
||||
|
|
||||
|
type Decode func(v interface{}) error |
||||
|
|
||||
|
func (s Decode) Unmarshal(v interface{}) error { |
||||
|
return s(v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseInt() (v int, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseInt64() (v int64, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseUint() (v uint, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseUint64() (v uint64, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseFloat64() (v float64, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseString() (v string, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseDuration() (v time.Duration, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseTime() (v time.Time, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Int() int { |
||||
|
in, _ := s.ParseInt() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Int64() int64 { |
||||
|
in, _ := s.ParseInt64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Uint() uint { |
||||
|
in, _ := s.ParseUint() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Uint64() uint64 { |
||||
|
in, _ := s.ParseUint64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Float64() float64 { |
||||
|
in, _ := s.ParseFloat64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Bytes() []byte { |
||||
|
return []byte(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) String() string { |
||||
|
v, _ := s.ParseString() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Bool() bool { |
||||
|
in, _ := s.ParseBool() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) ParseBool() (v bool, err error) { |
||||
|
return v, s.Unmarshal(&v) |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Duration() time.Duration { |
||||
|
in, _ := s.ParseDuration() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Decode) Time() time.Time { |
||||
|
in, _ := s.ParseTime() |
||||
|
|
||||
|
return in |
||||
|
} |
@ -0,0 +1,85 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
) |
||||
|
|
||||
|
type Empty struct { |
||||
|
Err error |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Unmarshal(val interface{}) error { |
||||
|
return e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseString() (string, error) { |
||||
|
return "", e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseInt() (int, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseInt64() (int64, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseUint() (uint, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseUint64() (uint64, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseFloat64() (float64, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseBool() (bool, error) { |
||||
|
return false, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseDuration() (time.Duration, error) { |
||||
|
return 0, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) ParseTime() (time.Time, error) { |
||||
|
return time.Time{}, e.Err |
||||
|
} |
||||
|
|
||||
|
func (e Empty) String() string { |
||||
|
return "" |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Int() int { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Int64() int64 { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Uint() uint { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Uint64() uint64 { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Float64() float64 { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Bool() bool { |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Duration() time.Duration { |
||||
|
return 0 |
||||
|
} |
||||
|
|
||||
|
func (e Empty) Time() time.Time { |
||||
|
return time.Time{} |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"fmt" |
||||
|
"strconv" |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
func ParseDuration(raw string) (time.Duration, error) { |
||||
|
d, err := time.ParseDuration(raw) |
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return d, nil |
||||
|
} |
||||
|
|
||||
|
func ParseInt(s string) (int64, error) { |
||||
|
i, err := strconv.ParseInt(s, 10, 64) |
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return i, nil |
||||
|
} |
||||
|
|
||||
|
func ParseUint(s string) (uint64, error) { |
||||
|
i, err := strconv.ParseUint(s, 10, 64) |
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return i, nil |
||||
|
} |
||||
|
|
||||
|
func Atoi(s string) (int, error) { |
||||
|
i, err := strconv.Atoi(s) |
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return i, nil |
||||
|
} |
||||
|
|
||||
|
func ParseTime(s string) (time.Time, error) { |
||||
|
i, err := time.Parse(time.RFC3339, s) |
||||
|
if err != nil { |
||||
|
return time.Time{}, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return i, nil |
||||
|
} |
||||
|
|
||||
|
func ParseFloat(s string) (float64, error) { |
||||
|
f, err := strconv.ParseFloat(s, 64) |
||||
|
if err != nil { |
||||
|
return 0, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return f, nil |
||||
|
} |
||||
|
|
||||
|
func ParseBool(s string) (bool, error) { |
||||
|
b, err := strconv.ParseBool(s) |
||||
|
if err != nil { |
||||
|
return false, fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return b, nil |
||||
|
} |
||||
|
|
||||
|
func JUnmarshal(b []byte, v interface{}) error { |
||||
|
if err := json.Unmarshal(b, v); err != nil { |
||||
|
return fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
@ -0,0 +1,112 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
var _ config.Value = (*JBytes)(nil) |
||||
|
|
||||
|
type JBytes []byte |
||||
|
|
||||
|
func (s JBytes) Unmarshal(v interface{}) error { |
||||
|
return JUnmarshal(s.Bytes(), v) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseString() (string, error) { |
||||
|
return s.String(), nil |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseInt() (int, error) { |
||||
|
return Atoi(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseInt64() (int64, error) { |
||||
|
return ParseInt(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseUint() (uint, error) { |
||||
|
u64, err := ParseUint(s.String()) |
||||
|
if err != nil { |
||||
|
return 0, err |
||||
|
} |
||||
|
|
||||
|
return uint(u64), nil |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseUint64() (uint64, error) { |
||||
|
return ParseUint(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseFloat64() (float64, error) { |
||||
|
return ParseFloat(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseBool() (bool, error) { |
||||
|
return ParseBool(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseDuration() (time.Duration, error) { |
||||
|
return ParseDuration(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) ParseTime() (time.Time, error) { |
||||
|
return ParseTime(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Bytes() []byte { |
||||
|
return []byte(s) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) String() string { |
||||
|
return string(s) |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Int() int { |
||||
|
in, _ := s.ParseInt() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Int64() int64 { |
||||
|
in, _ := s.ParseInt64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Uint() uint { |
||||
|
in, _ := s.ParseUint() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Uint64() uint64 { |
||||
|
in, _ := s.ParseUint64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Float64() float64 { |
||||
|
in, _ := s.ParseFloat64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Bool() bool { |
||||
|
in, _ := s.ParseBool() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Duration() time.Duration { |
||||
|
in, _ := s.ParseDuration() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JBytes) Time() time.Time { |
||||
|
in, _ := s.ParseTime() |
||||
|
|
||||
|
return in |
||||
|
} |
@ -0,0 +1,112 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
var _ config.Value = (*JString)(nil) |
||||
|
|
||||
|
type JString string |
||||
|
|
||||
|
func (s JString) Unmarshal(v interface{}) error { |
||||
|
return JUnmarshal(s.Bytes(), v) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseString() (string, error) { |
||||
|
return s.String(), nil |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseInt() (int, error) { |
||||
|
return Atoi(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseInt64() (int64, error) { |
||||
|
return ParseInt(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseUint() (uint, error) { |
||||
|
u64, err := ParseUint(s.String()) |
||||
|
if err != nil { |
||||
|
return 0, err |
||||
|
} |
||||
|
|
||||
|
return uint(u64), nil |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseUint64() (uint64, error) { |
||||
|
return ParseUint(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseFloat64() (float64, error) { |
||||
|
return ParseFloat(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseBool() (bool, error) { |
||||
|
return ParseBool(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseDuration() (time.Duration, error) { |
||||
|
return ParseDuration(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) ParseTime() (time.Time, error) { |
||||
|
return ParseTime(s.String()) |
||||
|
} |
||||
|
|
||||
|
func (s JString) Bytes() []byte { |
||||
|
return []byte(s) |
||||
|
} |
||||
|
|
||||
|
func (s JString) String() string { |
||||
|
return string(s) |
||||
|
} |
||||
|
|
||||
|
func (s JString) Int() int { |
||||
|
in, _ := s.ParseInt() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Int64() int64 { |
||||
|
in, _ := s.ParseInt64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Uint() uint { |
||||
|
in, _ := s.ParseUint() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Uint64() uint64 { |
||||
|
in, _ := s.ParseUint64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Float64() float64 { |
||||
|
in, _ := s.ParseFloat64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Bool() bool { |
||||
|
in, _ := s.ParseBool() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Duration() time.Duration { |
||||
|
in, _ := s.ParseDuration() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s JString) Time() time.Time { |
||||
|
in, _ := s.ParseTime() |
||||
|
|
||||
|
return in |
||||
|
} |
@ -0,0 +1,37 @@ |
|||||
|
package value_test |
||||
|
|
||||
|
import ( |
||||
|
"errors" |
||||
|
"testing" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/stretchr/testify/require" |
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
"gitoa.ru/go-4devs/config/value" |
||||
|
) |
||||
|
|
||||
|
func TestStringDuration(t *testing.T) { |
||||
|
t.Parallel() |
||||
|
|
||||
|
tests := map[string]struct { |
||||
|
raw value.JString |
||||
|
exp time.Duration |
||||
|
err error |
||||
|
}{ |
||||
|
"1m": { |
||||
|
raw: value.JString("1m"), |
||||
|
exp: time.Minute, |
||||
|
}, |
||||
|
"number error": { |
||||
|
raw: value.JString("100000000"), |
||||
|
err: config.ErrInvalidValue, |
||||
|
}, |
||||
|
} |
||||
|
|
||||
|
for name, data := range tests { |
||||
|
require.Equal(t, data.exp, data.raw.Duration(), name) |
||||
|
d, err := data.raw.ParseDuration() |
||||
|
require.Truef(t, errors.Is(err, data.err), "%[1]s: expect:%#[2]v, got:%#[3]v", name, data.err, err) |
||||
|
require.Equal(t, data.exp, d, name) |
||||
|
} |
||||
|
} |
@ -0,0 +1,158 @@ |
|||||
|
package value |
||||
|
|
||||
|
import ( |
||||
|
"encoding/json" |
||||
|
"fmt" |
||||
|
"time" |
||||
|
|
||||
|
"gitoa.ru/go-4devs/config" |
||||
|
) |
||||
|
|
||||
|
var _ config.Value = (*Value)(nil) |
||||
|
|
||||
|
type Value struct { |
||||
|
Val interface{} |
||||
|
} |
||||
|
|
||||
|
func (s Value) Int() int { |
||||
|
v, _ := s.ParseInt() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Int64() int64 { |
||||
|
v, _ := s.ParseInt64() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Uint() uint { |
||||
|
v, _ := s.ParseUint() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Uint64() uint64 { |
||||
|
v, _ := s.ParseUint64() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Float64() float64 { |
||||
|
in, _ := s.ParseFloat64() |
||||
|
|
||||
|
return in |
||||
|
} |
||||
|
|
||||
|
func (s Value) String() string { |
||||
|
v, _ := s.ParseString() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Bool() bool { |
||||
|
v, _ := s.ParseBool() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Duration() time.Duration { |
||||
|
v, _ := s.ParseDuration() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Raw() interface{} { |
||||
|
return s.Val |
||||
|
} |
||||
|
|
||||
|
func (s Value) Time() time.Time { |
||||
|
v, _ := s.ParseTime() |
||||
|
|
||||
|
return v |
||||
|
} |
||||
|
|
||||
|
func (s Value) Unmarshal(target interface{}) error { |
||||
|
if v, ok := s.Raw().([]byte); ok { |
||||
|
err := json.Unmarshal(v, target) |
||||
|
if err != nil { |
||||
|
return fmt.Errorf("%w: %s", config.ErrInvalidValue, err) |
||||
|
} |
||||
|
|
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
return config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseInt() (int, error) { |
||||
|
if r, ok := s.Raw().(int); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseInt64() (int64, error) { |
||||
|
if r, ok := s.Raw().(int64); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseUint() (uint, error) { |
||||
|
if r, ok := s.Raw().(uint); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseUint64() (uint64, error) { |
||||
|
if r, ok := s.Raw().(uint64); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseFloat64() (float64, error) { |
||||
|
if r, ok := s.Raw().(float64); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseString() (string, error) { |
||||
|
if r, ok := s.Raw().(string); ok { |
||||
|
return r, nil |
||||
|
} |
||||
|
|
||||
|
return "", config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseBool() (bool, error) { |
||||
|
if b, ok := s.Raw().(bool); ok { |
||||
|
return b, nil |
||||
|
} |
||||
|
|
||||
|
return false, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseDuration() (time.Duration, error) { |
||||
|
if b, ok := s.Raw().(time.Duration); ok { |
||||
|
return b, nil |
||||
|
} |
||||
|
|
||||
|
return 0, config.ErrInvalidValue |
||||
|
} |
||||
|
|
||||
|
func (s Value) ParseTime() (time.Time, error) { |
||||
|
if b, ok := s.Raw().(time.Time); ok { |
||||
|
return b, nil |
||||
|
} |
||||
|
|
||||
|
return time.Time{}, config.ErrInvalidValue |
||||
|
} |
@ -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() |
||||
|
} |
Loading…
Reference in new issue