File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,26 @@ func Parse(filename string, output Configurable) error {
127
127
return validator .New ().Struct (output )
128
128
}
129
129
130
+ // ParseWithValidator - parse config with custom validator. If validator is nil validation will be skipped.
131
+ func ParseWithValidator (filename string , val * validator.Validate , output Configurable ) error {
132
+ buf , err := readFile (filename )
133
+ if err != nil {
134
+ return err
135
+ }
136
+
137
+ if err := yaml .NewDecoder (buf ).Decode (output ); err != nil {
138
+ return err
139
+ }
140
+
141
+ if err := output .Substitute (); err != nil {
142
+ return err
143
+ }
144
+ if val != nil {
145
+ return val .Struct (output )
146
+ }
147
+ return nil
148
+ }
149
+
130
150
func readFile (filename string ) (* bytes.Buffer , error ) {
131
151
if filename == "" {
132
152
return nil , errors .Errorf ("you have to provide configuration filename" )
You can’t perform that action at this time.
0 commit comments