Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
e943421543 | |||
5fbf98760f | |||
c62fe465bf | |||
7d22067441 | |||
45631ab974 | |||
b1badeef63 | |||
64d820f251 | |||
bef606a7ee | |||
b39be29685 | |||
2b10a1e5b1 | |||
|
2add696dc8 | ||
|
7945c2cc71 | ||
9ffc9b6a21 | |||
|
e177ee76c0 | ||
2b3f80d430 | |||
|
0aeaaaecd3 | ||
e8707bb398 | |||
|
e1bf956f6d | ||
d39141e7a9 | |||
|
a4d99c6b13 | ||
6127475aa5 | |||
|
425034bcc7 | ||
ed3325aaf7 | |||
|
d97b510d8f | ||
456285c70d | |||
|
6af70b3805 | ||
5e02b42d4e | |||
|
292fc47f40 |
27
env.go
27
env.go
@ -1,4 +1,4 @@
|
|||||||
package env // import "go.unistack.org/micro-config-env/v3"
|
package env // import "go.unistack.org/micro-config-env/v4"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -8,9 +8,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/imdario/mergo"
|
"dario.cat/mergo"
|
||||||
"go.unistack.org/micro/v3/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
"go.unistack.org/micro/v4/options"
|
||||||
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultStructTag = "env"
|
var DefaultStructTag = "env"
|
||||||
@ -23,7 +24,7 @@ func (c *envConfig) Options() config.Options {
|
|||||||
return c.opts
|
return c.opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Init(opts ...config.Option) error {
|
func (c *envConfig) Init(opts ...options.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&c.opts)
|
o(&c.opts)
|
||||||
}
|
}
|
||||||
@ -39,7 +40,11 @@ func (c *envConfig) Init(opts ...config.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
|
func (c *envConfig) Load(ctx context.Context, opts ...options.Option) error {
|
||||||
|
if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := config.DefaultBeforeLoad(ctx, c); err != nil && !c.opts.AllowFail {
|
if err := config.DefaultBeforeLoad(ctx, c); err != nil && !c.opts.AllowFail {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -315,7 +320,11 @@ func fillValues(ctx context.Context, valueOf reflect.Value, structTag string) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
|
func (c *envConfig) Save(ctx context.Context, opts ...options.Option) error {
|
||||||
|
if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
options := config.NewSaveOptions(opts...)
|
options := config.NewSaveOptions(opts...)
|
||||||
|
|
||||||
if err := config.DefaultBeforeSave(ctx, c); err != nil && !c.opts.AllowFail {
|
if err := config.DefaultBeforeSave(ctx, c); err != nil && !c.opts.AllowFail {
|
||||||
@ -346,7 +355,7 @@ func (c *envConfig) Name() string {
|
|||||||
return c.opts.Name
|
return c.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *envConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
func (c *envConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
||||||
w := &envWatcher{
|
w := &envWatcher{
|
||||||
opts: c.opts,
|
opts: c.opts,
|
||||||
wopts: config.NewWatchOptions(opts...),
|
wopts: config.NewWatchOptions(opts...),
|
||||||
@ -360,7 +369,7 @@ func (c *envConfig) Watch(ctx context.Context, opts ...config.WatchOption) (conf
|
|||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(opts ...config.Option) config.Config {
|
func NewConfig(opts ...options.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/v3/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
10
go.mod
10
go.mod
@ -1,8 +1,10 @@
|
|||||||
module go.unistack.org/micro-config-env/v3
|
module go.unistack.org/micro-config-env/v4
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/imdario/mergo v0.3.13
|
dario.cat/mergo v1.0.0
|
||||||
go.unistack.org/micro/v3 v3.10.16
|
go.unistack.org/micro/v4 v4.0.15
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require github.com/google/uuid v1.5.0 // indirect
|
||||||
|
13
go.sum
13
go.sum
@ -1,10 +1,9 @@
|
|||||||
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||||
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||||
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
go.unistack.org/micro/v3 v3.10.16 h1:2er/SKKYbV60M+UuJM4eYCF0MZYAIq/yNUrAbTfgq8Q=
|
go.unistack.org/micro/v4 v4.0.15 h1:o4++RYX5guVPxfcJpP7VCj2Xr9BPFo6fj4+b5FStdEI=
|
||||||
go.unistack.org/micro/v3 v3.10.16/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q=
|
go.unistack.org/micro/v4 v4.0.15/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
||||||
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.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
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/v3/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
"go.unistack.org/micro/v3/util/jitter"
|
"go.unistack.org/micro/v4/util/jitter"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type envWatcher struct {
|
type envWatcher struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user