expvarmon/utils.go

29 lines
621 B
Go
Raw Normal View History

2015-05-01 21:49:19 +08:00
package main
import (
"errors"
"strings"
)
// ParseVars returns parsed and validated slice of strings with
// variables names that will be used for monitoring.
2015-05-01 23:48:34 +08:00
func ParseVars(def, extra string) ([]VarName, error) {
2015-05-01 21:49:19 +08:00
if def == "" && extra == "" {
return nil, errors.New("no vars specified")
}
2015-05-01 23:48:34 +08:00
fields := func(s string) []VarName {
ss := strings.FieldsFunc(s, func(r rune) bool { return r == ',' })
ret := []VarName{}
for _, str := range ss {
ret = append(ret, VarName(str))
}
return ret
2015-05-01 21:49:19 +08:00
}
2015-05-01 23:48:34 +08:00
var ret []VarName
2015-05-01 21:49:19 +08:00
ret = append(ret, fields(def)...)
ret = append(ret, fields(extra)...)
return ret, nil
}