-
Notifications
You must be signed in to change notification settings - Fork 3
/
development.go
46 lines (38 loc) · 979 Bytes
/
development.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
package clio
import (
"fmt"
"strings"
"github.com/anchore/fangs"
)
const (
ProfileCPU Profile = "cpu"
ProfileMem Profile = "mem"
ProfilingDisabled Profile = "none"
)
type Profile string
type DevelopmentConfig struct {
Profile Profile `yaml:"profile" json:"profile" mapstructure:"profile"`
}
func (d *DevelopmentConfig) DescribeFields(set fangs.FieldDescriptionSet) {
set.Add(&d.Profile, fmt.Sprintf("capture resource profiling data (available: [%s])", strings.Join([]string{string(ProfileCPU), string(ProfileMem)}, ", ")))
}
func (d *DevelopmentConfig) PostLoad() error {
p := parseProfile(string(d.Profile))
if p == "" {
return fmt.Errorf("invalid profile: %q", d.Profile)
}
d.Profile = p
return nil
}
func parseProfile(profile string) Profile {
switch strings.ToLower(profile) {
case "cpu":
return ProfileCPU
case "mem", "memory":
return ProfileMem
case "none", "", "disabled":
return ProfilingDisabled
default:
return ""
}
}