@@ -5,25 +5,29 @@ import (
5
5
"path/filepath"
6
6
)
7
7
8
- // NewFileProvider provides most functionality required to support a new file
8
+ // NewConfigFileType provides most functionality required to support a new file
9
9
// type. If manual unmarshaling is required, the Unmarshaler can be provided.
10
- func NewFileProvider (config ConfigImplementer , fileExtensions []string , unmarshaler Unmarshaler ) FileProvider {
11
- return FileProvider {
10
+ func NewConfigFileType (
11
+ config ConfigImplementer ,
12
+ fileExtensions []string ,
13
+ unmarshaler Unmarshaler ,
14
+ ) ConfigFileType {
15
+ return ConfigFileType {
12
16
unmarshaler : unmarshaler ,
13
17
Extensions : fileExtensions ,
14
18
ConfigType : ConfigType {
15
- Data : config ,
19
+ Config : config ,
16
20
},
17
21
}
18
22
}
19
23
20
- // Unmarshaler is a function that unmarshals a byte slice into a given interface.
24
+ // Unmarshaler unmarshals a byte slice into the given interface.
21
25
type Unmarshaler func (data []byte , v interface {}) error
22
26
23
- // FileProvider provides a ConfigImplementer that reads a file from disk and
24
- // unmarshals it into the Data field. Unmarshaling expects implementations to
27
+ // ConfigFileType provides a ConfigImplementer that reads a file from disk and
28
+ // unmarshals it into the Config field. Unmarshaling expects implementations to
25
29
// match the standard library interface for Unmarshal.
26
- type FileProvider struct {
30
+ type ConfigFileType struct {
27
31
// unmarshaler is a function that unmarshals a byte slice into a given
28
32
// interface.
29
33
unmarshaler Unmarshaler
@@ -37,7 +41,7 @@ type FileProvider struct {
37
41
}
38
42
39
43
// Stat checks if the file exists and computes the platform specific Path.
40
- func (f * FileProvider ) Stat (cfg * Config , dirPath string ) bool {
44
+ func (f * ConfigFileType ) Stat (cfg * Config , dirPath string ) bool {
41
45
for _ , ext := range f .Extensions {
42
46
cfgFilePath := dirPath + string (filepath .Separator ) + cfg .FileName + "." + ext
43
47
if _ , err := os .Stat (cfgFilePath ); err == nil {
@@ -49,22 +53,12 @@ func (f *FileProvider) Stat(cfg *Config, dirPath string) bool {
49
53
}
50
54
51
55
// Parse reads the file based on the generated path computed from Stat and
52
- // unmarshals it into the Data field.
53
- func (f * FileProvider ) Parse (_ * Config ) error {
56
+ // unmarshals it into the Config field.
57
+ func (f * ConfigFileType ) Parse (_ * Config ) error {
54
58
file , err := os .ReadFile (f .Path )
55
59
if err != nil {
56
60
return err
57
61
}
58
62
59
- return f .unmarshaler (file , f .Data )
60
- }
61
-
62
- // Validate calls the Data's validation function.
63
- func (f * FileProvider ) Validate () error {
64
- return f .Data .Validate ()
65
- }
66
-
67
- // Merge calls the Data's merge function.
68
- func (f * FileProvider ) Merge (t any ) any {
69
- return f .Data .Merge (t )
63
+ return f .unmarshaler (file , f .Config )
70
64
}
0 commit comments