-
Notifications
You must be signed in to change notification settings - Fork 53
/
option.go
56 lines (48 loc) · 1.78 KB
/
option.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
/*
*
* Copyright (C) 2023 Antigloss Huang (https://github.com/antigloss) All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package file
import "github.com/antigloss/go/conf/tdata"
// ConfigPath holds path to the local configuration file/directory
type ConfigPath struct {
Path string // path to the local configuration file/directory. If it's a directory, then all files under the directory will also be read, excluding those start with a dot (.)
Recursive bool // true for reading files under `Path` recursively, false for reading only the files right under directory `Path`
}
// WithConfigPaths sets paths to local configuration files
func WithConfigPaths(paths ...ConfigPath) option {
return func(o *options) {
o.paths = paths
}
}
// WithTemplateData sets template data source.
// Will use configurations from `tData` to replace templates in the configurations from local files
func WithTemplateData(tData tdata.TemplateData) option {
return func(o *options) {
o.tData = tData
}
}
type option func(options *options)
type options struct {
paths []ConfigPath
tData tdata.TemplateData
}
func (o *options) apply(opts ...option) {
for _, opt := range opts {
opt(o)
}
}