-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.tpl
51 lines (36 loc) · 2.09 KB
/
value.tpl
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
package env
import "strconv"
type {{ .Type }}Value {{ .Type }}
func new{{ .TypeName }}Value(val {{ .Type }}, p *{{ .Type }}) *{{ .Type }}Value {
*p = val
return (*{{ .Type }}Value)(p)
}
func ({{ .Receiver }} *{{ .Type }}Value) Set(val string) error {
v, err := {{ .ParseFunc }}
*{{ .Receiver }} = {{ .Type }}Value(v)
return err
}
func (*{{ .Type }}Value) Type() string { return "{{ .Type }}" }
func ({{ .Receiver }} *{{ .Type }}Value) String() string { return {{ .FormatFunc }} }
// {{ .TypeName }}Var defines {{ .Article }} {{ .Type }} environment variable with specified name, default value, and usage string.
// The argument p points to {{ .Article }} {{ .Type }} variable in which to store the value of the environment variable.
func (s *EnvVarSet) {{ .TypeName }}Var(p *{{ .Type }}, name string, value {{ .Type }}, usage string) {
s.Var(new{{ .TypeName }}Value(value, p), name, usage)
}
// {{ .TypeName }} defines {{ .Article }} {{ .Type }} environment variable with specified name, default value, and usage string.
// The return value is the address of {{ .Article }} {{ .Type }} variable that stores the value of the environment variable.
func (s *EnvVarSet) {{ .TypeName }}(name string, value {{ .Type }}, usage string) *{{ .Type }} {
p := new({{ .Type }})
s.{{ .TypeName }}Var(p, name, value, usage)
return p
}
// {{ .TypeName }}Var defines {{ .Article }} {{ .Type }} environment variable with specified name, default value, and usage string.
// The argument p points to {{ .Article }} {{ .Type }} variable in which to store the value of the environment variable.
func {{ .TypeName }}Var(p *{{ .Type }}, name string, value {{ .Type }}, usage string) {
Environment.{{ .TypeName }}Var(p, name, value, usage)
}
// {{ .TypeName }} defines {{ .Article }} {{ .Type }} environment variable with specified name, default value, and usage string.
// The return value is the address of {{ .Article }} {{ .Type }} variable that stores the value of the environment variable.
func {{ .TypeName }}(name string, value {{ .Type }}, usage string) *{{ .Type }} {
return Environment.{{ .TypeName }}(name, value, usage)
}