-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.go
More file actions
60 lines (46 loc) · 978 Bytes
/
config.go
File metadata and controls
60 lines (46 loc) · 978 Bytes
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
package exec
import (
"fmt"
"reflect"
"strings"
"time"
)
type config struct {
Name string
value interface{}
}
func (c *config) Value() interface{} {
v := reflect.ValueOf(c.value)
if v.Kind() == reflect.Func {
t := v.Type()
if t.NumIn() != 0 {
panic("Function type must have no input parameters")
}
if t.NumOut() != 1 {
panic("Function type must have a single return value")
}
if t.Out(0).Kind().String() != "interface" {
panic("Function return value must be an interface{}")
}
c.value = v.Call(nil)[0].Interface()
}
return c.value
}
func (c *config) String() string {
return strings.TrimSpace(fmt.Sprint(c.Value()))
}
func (c *config) Int() int {
return c.Value().(int)
}
func (c *config) Int64() int64 {
return c.Value().(int64)
}
func (c *config) Bool() bool {
return c.Value().(bool)
}
func (c *config) Slice() []string {
return c.Value().([]string)
}
func (c *config) Time() time.Time {
return c.Value().(time.Time)
}