update for latest micro changes #96
14
file.go
14
file.go
@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||
)
|
||||
|
||||
@ -24,7 +24,7 @@ func (c *fileConfig) Options() config.Options {
|
||||
return c.opts
|
||||
}
|
||||
|
||||
func (c *fileConfig) Init(opts ...config.Option) error {
|
||||
func (c *fileConfig) Init(opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -53,7 +53,7 @@ func (c *fileConfig) Init(opts ...config.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
|
||||
func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeLoad(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
|
||||
|
||||
defer fp.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize)))
|
||||
buf, err := io.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize)))
|
||||
if err != nil {
|
||||
if !c.opts.AllowFail {
|
||||
return err
|
||||
@ -124,7 +124,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...config.LoadOption) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fileConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
|
||||
func (c *fileConfig) Save(ctx context.Context, opts ...options.Option) error {
|
||||
if err := config.DefaultBeforeSave(ctx, c); err != nil && !c.opts.AllowFail {
|
||||
return err
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (c *fileConfig) Name() string {
|
||||
return c.opts.Name
|
||||
}
|
||||
|
||||
func (c *fileConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
||||
func (c *fileConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
||||
path := c.path
|
||||
options := config.NewWatchOptions(opts...)
|
||||
if options.Context != nil {
|
||||
@ -213,7 +213,7 @@ func (c *fileConfig) Watch(ctx context.Context, opts ...config.WatchOption) (con
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func NewConfig(opts ...config.Option) config.Config {
|
||||
func NewConfig(opts ...options.Option) config.Config {
|
||||
options := config.NewOptions(opts...)
|
||||
if len(options.StructTag) == 0 {
|
||||
options.StructTag = DefaultStructTag
|
||||
|
6
go.mod
6
go.mod
@ -3,6 +3,8 @@ module go.unistack.org/micro-config-file/v4
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/imdario/mergo v0.3.14
|
||||
go.unistack.org/micro/v4 v4.0.1
|
||||
github.com/imdario/mergo v0.3.16
|
||||
go.unistack.org/micro/v4 v4.0.6
|
||||
)
|
||||
|
||||
require github.com/google/uuid v1.3.0 // indirect
|
||||
|
9
go.sum
9
go.sum
@ -1,7 +1,12 @@
|
||||
github.com/imdario/mergo v0.3.14 h1:fOqeC1+nCuuk6PKQdg9YmosXX7Y7mHX6R/0ZldI9iHo=
|
||||
github.com/imdario/mergo v0.3.14/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
|
||||
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
|
||||
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||
go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
|
||||
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
||||
go.unistack.org/micro/v4 v4.0.6 h1:YFWvTh3VwyOd6NHYTQcf47n2TF5+p/EhpnbuBQX3qhk=
|
||||
go.unistack.org/micro/v4 v4.0.6/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk=
|
||||
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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
18
options.go
18
options.go
@ -1,23 +1,11 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
)
|
||||
|
||||
type pathKey struct{}
|
||||
|
||||
func Path(path string) config.Option {
|
||||
return config.SetOption(pathKey{}, path)
|
||||
}
|
||||
|
||||
func LoadPath(path string) config.LoadOption {
|
||||
return config.SetLoadOption(pathKey{}, path)
|
||||
}
|
||||
|
||||
func SavePath(path string) config.SaveOption {
|
||||
return config.SetSaveOption(pathKey{}, path)
|
||||
}
|
||||
|
||||
func WatchPath(path string) config.WatchOption {
|
||||
return config.SetWatchOption(pathKey{}, path)
|
||||
func Path(path string) options.Option {
|
||||
return options.ContextOption(pathKey{}, path)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user