Debian Codegraph @

providers/rawbytes/rawbytes.go

raw
1 // Package rawbytes implements a koanf.Provider that takes a []byte slice
2 // and provides it to koanf to be parsed by a koanf.Parser.
3 package rawbytes
4
5 import (
6 "errors"
7 )
8
9 // RawBytes implements a raw bytes provider.
10 type RawBytes struct {
11 b []byte
12 }
13
14 // Provider returns a provider that takes a raw []byte slice to be parsed
15 // by a koanf.Parser parser. This should be a nested conf map, like the
16 // contents of a raw JSON config file.
17 func Provider(b []byte) *RawBytes {
18 r := &RawBytes{b: make([]byte, len(b))}
19 copy(r.b[:], b)
20 return r
21 }
22
23 // ReadBytes returns the raw bytes for parsing.
24 func (r *RawBytes) ReadBytes() ([]byte, error) {
25 return r.b, nil
26 }
27
28 // Read is not supported by rawbytes provider.
29 func (r *RawBytes) Read() (map[string]any, error) {
30 return nil, errors.New("rawbytes provider does not support this method")
31 }