1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-03-03 15:22:30 +02:00
Benjamin 5d5aee1f08
replace ioutil with io and os (#2327)
set the go version to 1.16 in pr.yml and tests.yml, so as to be consistent with the version in go.mod.
2021-10-30 19:24:40 +01:00

68 lines
1.1 KiB
Go

package pkger
import (
"io"
"github.com/markbates/pkger"
"go-micro.dev/v4/config/source"
)
type file struct {
path string
opts source.Options
}
var (
DefaultPath = "/config.yaml"
)
func (f *file) Read() (*source.ChangeSet, error) {
fh, err := pkger.Open(f.path)
if err != nil {
return nil, err
}
defer fh.Close()
b, err := io.ReadAll(fh)
if err != nil {
return nil, err
}
info, err := fh.Stat()
if err != nil {
return nil, err
}
cs := &source.ChangeSet{
Format: format(f.path, f.opts.Encoder),
Source: f.String(),
Timestamp: info.ModTime(),
Data: b,
}
cs.Checksum = cs.Sum()
return cs, nil
}
func (f *file) Watch() (source.Watcher, error) {
return source.NewNoopWatcher()
}
// Write is unsupported
func (f *file) Write(cs *source.ChangeSet) error {
return nil
}
func (f *file) String() string {
return "pkger"
}
func NewSource(opts ...source.Option) source.Source {
options := source.NewOptions(opts...)
path := DefaultPath
f, ok := options.Context.Value(pkgerPathKey{}).(string)
if ok {
path = f
}
return &file{opts: options, path: path}
}