Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4707d7b1d | |||
b7d4e2e11e |
17
env.go
17
env.go
@ -1,4 +1,4 @@
|
|||||||
package env // import "go.unistack.org/micro-config-env/v4"
|
package env
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -9,9 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v3/config"
|
||||||
"go.unistack.org/micro/v4/options"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultStructTag = "env"
|
var DefaultStructTag = "env"
|
||||||
@ -24,7 +23,7 @@ func (c *envConfig) Options() config.Options {
|
|||||||
return c.opts
|
return c.opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Init(opts ...options.Option) error {
|
func (c *envConfig) Init(opts ...config.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&c.opts)
|
o(&c.opts)
|
||||||
}
|
}
|
||||||
@ -40,7 +39,7 @@ func (c *envConfig) Init(opts ...options.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Load(ctx context.Context, opts ...options.Option) error {
|
func (c *envConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
|
||||||
if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
|
if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -320,7 +319,7 @@ func fillValues(ctx context.Context, valueOf reflect.Value, structTag string) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Save(ctx context.Context, opts ...options.Option) error {
|
func (c *envConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
|
||||||
if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
|
if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -355,7 +354,7 @@ func (c *envConfig) Name() string {
|
|||||||
return c.opts.Name
|
return c.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
func (c *envConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
||||||
w := &envWatcher{
|
w := &envWatcher{
|
||||||
opts: c.opts,
|
opts: c.opts,
|
||||||
wopts: config.NewWatchOptions(opts...),
|
wopts: config.NewWatchOptions(opts...),
|
||||||
@ -369,7 +368,7 @@ func (c *envConfig) Watch(ctx context.Context, opts ...options.Option) (config.W
|
|||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(opts ...options.Option) config.Config {
|
func NewConfig(opts ...config.Option) config.Config {
|
||||||
options := config.NewOptions(opts...)
|
options := config.NewOptions(opts...)
|
||||||
if len(options.StructTag) == 0 {
|
if len(options.StructTag) == 0 {
|
||||||
options.StructTag = DefaultStructTag
|
options.StructTag = DefaultStructTag
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v3/config"
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
6
go.mod
6
go.mod
@ -1,10 +1,10 @@
|
|||||||
module go.unistack.org/micro-config-env/v4
|
module go.unistack.org/micro-config-env/v3
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
dario.cat/mergo v1.0.0
|
dario.cat/mergo v1.0.0
|
||||||
go.unistack.org/micro/v4 v4.0.15
|
go.unistack.org/micro/v3 v3.10.44
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/google/uuid v1.5.0 // indirect
|
require github.com/google/uuid v1.6.0 // indirect
|
||||||
|
8
go.sum
8
go.sum
@ -1,9 +1,9 @@
|
|||||||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
go.unistack.org/micro/v4 v4.0.15 h1:o4++RYX5guVPxfcJpP7VCj2Xr9BPFo6fj4+b5FStdEI=
|
go.unistack.org/micro/v3 v3.10.44 h1:Vgyy9BrJOSdFvo29/klrgIBE/Nme9E8udPAljos34o0=
|
||||||
go.unistack.org/micro/v4 v4.0.15/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
go.unistack.org/micro/v3 v3.10.44/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@ -3,9 +3,9 @@ package env
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v3/config"
|
||||||
"go.unistack.org/micro/v4/util/jitter"
|
"go.unistack.org/micro/v3/util/jitter"
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type envWatcher struct {
|
type envWatcher struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user