-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.go
99 lines (80 loc) · 1.73 KB
/
fs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//go:build go1.16
// +build go1.16
package fs
import (
"io"
"io/fs"
"github.com/hedzr/store"
)
func New(fs fs.FS, pathname string, opts ...Opt) *pvdr {
s := &pvdr{FS: fs, path: pathname}
for _, opt := range opts {
opt(s)
}
return s
}
type Opt func(s *pvdr)
type pvdr struct {
fs.FS
path string
prefix string
codec store.Codec
}
func WithCodec(codec store.Codec) Opt {
return func(s *pvdr) {
s.codec = codec
}
}
func WithPosition(prefix string) Opt {
return func(s *pvdr) {
s.prefix = prefix
}
}
func (s *pvdr) GetCodec() (codec store.Codec) { return s.codec }
func (s *pvdr) GetPosition() (pos string) { return s.prefix }
func (s *pvdr) WithCodec(codec store.Codec) { s.codec = codec }
func (s *pvdr) WithPosition(prefix string) { s.prefix = prefix }
func (s *pvdr) Count() int {
return 0
}
func (s *pvdr) Has(key string) bool {
return false
}
func (s *pvdr) Next() (key string, eol bool) {
eol = true
return
}
func (s *pvdr) Keys() (keys []string, err error) {
err = store.ErrNotImplemented
return
}
func (s *pvdr) Value(key string) (value interface{}, ok bool) {
ok = false
return
}
func (s *pvdr) MustValue(key string) (value interface{}) {
return
}
func (s *pvdr) Reader() (r store.Reader, err error) {
err = store.ErrNotImplemented
return
}
// Read returns the loaded map[string]interface{}.
func (s *pvdr) Read() (data map[string]store.ValPkg, err error) {
err = store.ErrNotImplemented
return
}
// ReadBytes is not supported by the confmap provider.
func (s *pvdr) ReadBytes() (data []byte, err error) {
var f fs.File
f, err = s.Open(s.path)
if err != nil {
return
}
defer f.Close()
return io.ReadAll(f)
}
func (s *pvdr) Write(data []byte) (err error) {
err = store.ErrNotImplemented
return
}