-
Notifications
You must be signed in to change notification settings - Fork 1
/
factorcfg.go
64 lines (54 loc) · 1.47 KB
/
factorcfg.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
package factorcfg
import (
"errors"
"fmt"
"reflect"
"strings"
)
type KeyMapper func([]string) string
// ErrInvalidSpecification indicates that a specification is of the wrong type.
var ErrInvalidSpecification = errors.New("invalid specification: must be a struct")
// A ParseError occurs when an environment variable cannot be converted to
// the type required by a struct field during assignment.
type ParseError struct {
FieldName string
TypeName string
Value interface{}
}
func (e *ParseError) Error() string {
return fmt.Sprintf("assigning to %s: converting '%s' to an %s", e.FieldName, e.Value, e.TypeName)
}
type RequiredError struct {
Name string
Tags map[string]string
}
func (e *RequiredError) Error() string {
return fmt.Sprintf("config \"%s\" is required", e.Name)
}
// TemplateField is a structure used when rendering
// a template of the spec.
type TemplateField struct {
Name string
Value interface{}
String string
Type reflect.Type
Tags map[string]string
}
func stringInSlice(list []string, a string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
// trimsplit slices s into all substrings separated by sep and returns a
// slice of the substrings between the separator with all leading and trailing
// white space removed, as defined by Unicode.
func trimsplit(s, sep string) []string {
trimmed := strings.Split(s, sep)
for i := range trimmed {
trimmed[i] = strings.TrimSpace(trimmed[i])
}
return trimmed
}