This commit is contained in:
@@ -10,7 +10,8 @@ steps:
|
|||||||
- name: test
|
- name: test
|
||||||
image: golang
|
image: golang
|
||||||
commands:
|
commands:
|
||||||
- go test -parallel 10 -race ./...
|
# - go test -parallel 10 -race ./...
|
||||||
|
- go test -race ./...
|
||||||
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
image: golangci/golangci-lint:v1.53
|
image: golangci/golangci-lint:v1.53
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ linters:
|
|||||||
- ifshort
|
- ifshort
|
||||||
- nosnakecase
|
- nosnakecase
|
||||||
|
|
||||||
|
- ireturn # implement provider interface
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ func (c *Client) Value(ctx context.Context, path ...string) (Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Watch(ctx context.Context, callback WatchCallback, path ...string) error {
|
func (c *Client) Watch(ctx context.Context, callback WatchCallback, path ...string) error {
|
||||||
|
|
||||||
for idx, prov := range c.providers {
|
for idx, prov := range c.providers {
|
||||||
provider, ok := prov.(WatchProvider)
|
provider, ok := prov.(WatchProvider)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ func (p *Provider) Name() string {
|
|||||||
return p.name
|
return p.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, error) {
|
func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) {
|
||||||
if err := p.parse(); err != nil {
|
if err := p.parse(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,11 @@ func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
return value.Decode(func(v interface{}) error {
|
return value.Decode(func(v interface{}) error {
|
||||||
return json.Unmarshal(data, v)
|
if err := json.Unmarshal(data, v); err != nil {
|
||||||
|
return fmt.Errorf("unmarshal:%w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ func (d *Duration) UnmarshalJSON(in []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("parse:%w", err)
|
return fmt.Errorf("parse:%w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Duration = o
|
d.Duration = o
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
2
provider/env/provider.go
vendored
2
provider/env/provider.go
vendored
@@ -45,7 +45,7 @@ func (p *Provider) Name() string {
|
|||||||
return p.name
|
return p.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) Value(ctx context.Context, path ...string) (config.Value, error) {
|
func (p *Provider) Value(_ context.Context, path ...string) (config.Value, error) {
|
||||||
name := p.prefix + p.key(path...)
|
name := p.prefix + p.key(path...)
|
||||||
if val, ok := os.LookupEnv(name); ok {
|
if val, ok := os.LookupEnv(name); ok {
|
||||||
return value.JString(val), nil
|
return value.JString(val), nil
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ func (p *Provider) Watch(ctx context.Context, callback config.WatchCallback, key
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.logger(ctx, "callback %v:%v", key, err)
|
p.logger(ctx, "callback %v:%v", key, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
oldVar = newVar
|
oldVar = newVar
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package watcher_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -14,6 +14,8 @@ import (
|
|||||||
"gitoa.ru/go-4devs/config/value"
|
"gitoa.ru/go-4devs/config/value"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ config.Provider = (*provider)(nil)
|
||||||
|
|
||||||
type provider struct {
|
type provider struct {
|
||||||
cnt int32
|
cnt int32
|
||||||
}
|
}
|
||||||
@@ -25,7 +27,7 @@ func (p *provider) Name() string {
|
|||||||
func (p *provider) Value(context.Context, ...string) (config.Value, error) {
|
func (p *provider) Value(context.Context, ...string) (config.Value, error) {
|
||||||
p.cnt++
|
p.cnt++
|
||||||
|
|
||||||
return value.JString(fmt.Sprint(p.cnt)), nil
|
return value.JString(strconv.Itoa(int(p.cnt))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatcher(t *testing.T) {
|
func TestWatcher(t *testing.T) {
|
||||||
@@ -57,6 +59,7 @@ func TestWatcher(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"tmpname",
|
"tmpname",
|
||||||
)
|
)
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -26,10 +26,8 @@ func Run(t *testing.T, provider config.Provider, read []Read) {
|
|||||||
val, err := provider.Value(ctx, read.Key...)
|
val, err := provider.Value(ctx, read.Key...)
|
||||||
require.NoError(t, err, read.Key)
|
require.NoError(t, err, read.Key)
|
||||||
read.Assert(t, val)
|
read.Assert(t, val)
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Read struct {
|
type Read struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user