Compare commits
84 Commits
Author | SHA1 | Date | |
---|---|---|---|
bb3f6c2a7c | |||
b579ffb5ea | |||
6b4202956e | |||
37e0380939 | |||
|
3cac13e35b | ||
d52e22c187 | |||
3cc1cf899a | |||
89b41364c3 | |||
d7ffcd19f8 | |||
6b27204711 | |||
4bee1a7041 | |||
f8f36b157f | |||
7018485fde | |||
dcae9f14ee | |||
510dd16e48 | |||
|
257964fb26 | ||
11fe3f3ef7 | |||
|
ba9aa37eae | ||
d54d71403c | |||
|
d9c127339d | ||
2290d7573b | |||
|
7f449da60b | ||
c01614781a | |||
|
95606b8f21 | ||
c70f6386d0 | |||
|
28c896b8fb | ||
|
0c0e1307bd | ||
|
1f82ecea93 | ||
76101e6ce1 | |||
|
b830dc9749 | ||
8988703465 | |||
|
0ec641747a | ||
fa03d3b557 | |||
|
2cebca91a6 | ||
5204de7cbb | |||
|
dcebdb62f2 | ||
5877222e8a | |||
|
811c83a189 | ||
0b610c430e | |||
|
e441398ab4 | ||
|
df29357782 | ||
dc0b42f998 | |||
|
c9657f0b20 | ||
150d1e57f6 | |||
|
2c31e3b350 | ||
|
7794d7a281 | ||
|
083ef551a0 | ||
|
0ecb1c1659 | ||
|
e49cae189a | ||
909ad599bb | |||
|
784b309405 | ||
9f71fdea5f | |||
|
dc84a2eb2a | ||
|
ad3e3e3247 | ||
|
006ed2929c | ||
3920f11b69 | |||
|
a84556fc6f | ||
|
6a936fa610 | ||
|
a358f95f2e | ||
23e0b7671b | |||
|
a60d877ed1 | ||
3728d5ed05 | |||
|
2ee7357913 | ||
4fbfd6da4d | |||
|
747def6210 | ||
f5fe1f7318 | |||
|
792d9734c2 | ||
697673296b | |||
|
58860cbb4c | ||
76722cd0de | |||
764e827a9e | |||
|
0f185974fe | ||
|
659f0a2446 | ||
|
345f9cc563 | ||
|
d1b85de9ec | ||
|
4fc4a78a77 | ||
|
f9828bcbf2 | ||
|
5810834afd | ||
|
ca1d9e8da5 | ||
|
bded061837 | ||
|
93c1ac7971 | ||
|
3cce97dc16 | ||
|
b09c5e52e3 | ||
2de3b60cd3 |
36
file.go
36
file.go
@@ -8,14 +8,15 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
"go.unistack.org/micro/v4/codec"
|
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
"go.unistack.org/micro/v4/options"
|
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultStructTag = "file"
|
var (
|
||||||
|
DefaultStructTag = "file"
|
||||||
|
MaxFileSize int64 = 1 * 1024 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
type fileConfig struct {
|
type fileConfig struct {
|
||||||
opts config.Options
|
opts config.Options
|
||||||
@@ -28,17 +29,13 @@ func (c *fileConfig) Options() config.Options {
|
|||||||
return c.opts
|
return c.opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileConfig) Init(opts ...options.Option) error {
|
func (c *fileConfig) Init(opts ...config.Option) error {
|
||||||
var err error
|
if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
||||||
|
|
||||||
if err = config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err = o(&c.opts); err != nil {
|
o(&c.opts)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.opts.Context != nil {
|
if c.opts.Context != nil {
|
||||||
@@ -57,13 +54,6 @@ func (c *fileConfig) Init(opts ...options.Option) error {
|
|||||||
return fmt.Errorf("Codec must be specified")
|
return fmt.Errorf("Codec must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.path == "" && c.reader == nil {
|
|
||||||
err := fmt.Errorf("Path or Reader must be specified")
|
|
||||||
if !c.opts.AllowFail {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := config.DefaultAfterInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
if err := config.DefaultAfterInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -71,7 +61,7 @@ func (c *fileConfig) Init(opts ...options.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error {
|
func (c *fileConfig) 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
|
||||||
}
|
}
|
||||||
@@ -100,7 +90,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error {
|
|||||||
var fp io.Reader
|
var fp io.Reader
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.path != "" {
|
if path != "" {
|
||||||
fp, err = os.OpenFile(path, os.O_RDONLY, os.FileMode(0o400))
|
fp, err = os.OpenFile(path, os.O_RDONLY, os.FileMode(0o400))
|
||||||
} else if c.reader != nil {
|
} else if c.reader != nil {
|
||||||
fp = reader
|
fp = reader
|
||||||
@@ -134,7 +124,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error {
|
|||||||
r = fp
|
r = fp
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := io.ReadAll(io.LimitReader(r, int64(codec.DefaultMaxMsgSize)))
|
buf, err := io.ReadAll(io.LimitReader(r, MaxFileSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !c.opts.AllowFail {
|
if !c.opts.AllowFail {
|
||||||
return err
|
return err
|
||||||
@@ -178,7 +168,7 @@ func (c *fileConfig) Load(ctx context.Context, opts ...options.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileConfig) Save(ctx context.Context, opts ...options.Option) error {
|
func (c *fileConfig) 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
|
||||||
}
|
}
|
||||||
@@ -248,7 +238,7 @@ func (c *fileConfig) Name() string {
|
|||||||
return c.opts.Name
|
return c.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fileConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
func (c *fileConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
||||||
path := c.path
|
path := c.path
|
||||||
options := config.NewWatchOptions(opts...)
|
options := config.NewWatchOptions(opts...)
|
||||||
if options.Context != nil {
|
if options.Context != nil {
|
||||||
@@ -271,7 +261,7 @@ func (c *fileConfig) Watch(ctx context.Context, opts ...options.Option) (config.
|
|||||||
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
|
||||||
|
16
file_test.go
16
file_test.go
@@ -4,13 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
"go.unistack.org/micro/v4/options"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type jsoncodec struct{}
|
type jsoncodec struct{}
|
||||||
@@ -23,22 +21,10 @@ func (*jsoncodec) Unmarshal(buf []byte, v interface{}, opts ...codec.Option) err
|
|||||||
return json.Unmarshal(buf, v)
|
return json.Unmarshal(buf, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*jsoncodec) ReadBody(r io.Reader, v interface{}) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*jsoncodec) ReadHeader(r io.Reader, m *codec.Message, t codec.MessageType) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*jsoncodec) String() string {
|
func (*jsoncodec) String() string {
|
||||||
return "json"
|
return "json"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*jsoncodec) Write(w io.Writer, m *codec.Message, v interface{}) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadReplace(t *testing.T) {
|
func TestLoadReplace(t *testing.T) {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Key string
|
Key string
|
||||||
@@ -52,7 +38,7 @@ func TestLoadReplace(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
c := NewConfig(options.Codec(
|
c := NewConfig(config.Codec(
|
||||||
&jsoncodec{}),
|
&jsoncodec{}),
|
||||||
config.Struct(cfg),
|
config.Struct(cfg),
|
||||||
Reader(buf),
|
Reader(buf),
|
||||||
|
20
go.mod
20
go.mod
@@ -1,10 +1,22 @@
|
|||||||
module go.unistack.org/micro-config-file/v4
|
module go.unistack.org/micro-config-file/v4
|
||||||
|
|
||||||
go 1.20
|
go 1.22.0
|
||||||
|
|
||||||
|
toolchain go1.24.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
dario.cat/mergo v1.0.0
|
dario.cat/mergo v1.0.1
|
||||||
go.unistack.org/micro/v4 v4.0.17
|
go.unistack.org/micro/v4 v4.1.3
|
||||||
|
golang.org/x/text v0.21.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require github.com/google/uuid v1.6.0 // indirect
|
require (
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 // indirect
|
||||||
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
|
go.unistack.org/micro-proto/v4 v4.1.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.3 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
34
go.sum
34
go.sum
@@ -1,9 +1,35 @@
|
|||||||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
|
||||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4=
|
||||||
|
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||||
|
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.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.17 h1:mF7uM+J4ILdG+1fcwzKYCwDlxhdbF/e1WnGzKKLnIXc=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
go.unistack.org/micro/v4 v4.0.17/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4=
|
||||||
|
github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
|
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||||
|
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||||
|
go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk=
|
||||||
|
go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
|
||||||
|
go.unistack.org/micro/v4 v4.1.3 h1:9QHiLHBTfPtfKyoY3HsLPNVSK0wlAAoMV+9saLz2iR4=
|
||||||
|
go.unistack.org/micro/v4 v4.1.3/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw=
|
||||||
|
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||||
|
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||||
|
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
|
||||||
|
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
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/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
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=
|
||||||
|
26
options.go
26
options.go
@@ -5,28 +5,40 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/options"
|
"go.unistack.org/micro/v4/config"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pathKey struct{}
|
type pathKey struct{}
|
||||||
|
|
||||||
func Path(path string) options.Option {
|
func Path(path string) config.Option {
|
||||||
return options.ContextOption(pathKey{}, path)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type readerKey struct{}
|
type readerKey struct{}
|
||||||
|
|
||||||
func Reader(r io.Reader) options.Option {
|
func Reader(r io.Reader) config.Option {
|
||||||
return options.ContextOption(readerKey{}, r)
|
return config.SetOption(readerKey{}, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
type transformerKey struct{}
|
type transformerKey struct{}
|
||||||
|
|
||||||
type TransformerFunc func(src []byte, index []int) []byte
|
type TransformerFunc func(src []byte, index []int) []byte
|
||||||
|
|
||||||
func Transformer(t transform.Transformer) options.Option {
|
func Transformer(t transform.Transformer) config.Option {
|
||||||
return options.ContextOption(transformerKey{}, t)
|
return config.SetOption(transformerKey{}, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvTransformer(rs string, trimLeft, trimRight int) (*EnvTransformer, error) {
|
func NewEnvTransformer(rs string, trimLeft, trimRight int) (*EnvTransformer, error) {
|
||||||
|
@@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"go.unistack.org/micro/v4/codec"
|
|
||||||
"go.unistack.org/micro/v4/config"
|
"go.unistack.org/micro/v4/config"
|
||||||
"go.unistack.org/micro/v4/util/jitter"
|
"go.unistack.org/micro/v4/util/jitter"
|
||||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||||
@@ -38,12 +37,12 @@ func (w *fileWatcher) run() {
|
|||||||
dst, err := rutil.Zero(src)
|
dst, err := rutil.Zero(src)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
var fp *os.File
|
var fp *os.File
|
||||||
if fp, err = os.OpenFile(w.path, os.O_RDONLY, os.FileMode(0400)); err != nil {
|
if fp, err = os.OpenFile(w.path, os.O_RDONLY, os.FileMode(0o400)); err != nil {
|
||||||
w.echan <- fmt.Errorf("failed to open: %s, error: %w", w.path, err)
|
w.echan <- fmt.Errorf("failed to open: %s, error: %w", w.path, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var buf []byte
|
var buf []byte
|
||||||
buf, err = io.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize)))
|
buf, err = io.ReadAll(io.LimitReader(fp, MaxFileSize))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = w.opts.Codec.Unmarshal(buf, dst)
|
err = w.opts.Codec.Unmarshal(buf, dst)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user