Skip to content

Commit

Permalink
fix to private scope
Browse files Browse the repository at this point in the history
  • Loading branch information
yseto committed Sep 27, 2023
1 parent 05d1c30 commit cea26f1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions asstatusparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"golang.org/x/exp/slices"
)

var Keywords = []string{"OK", "WARNING", "CRITICAL", "UNKNOWN"}
var keywords = []string{"OK", "WARNING", "CRITICAL", "UNKNOWN"}

func StrToStatus(s string) Status {
func strToStatus(s string) Status {
switch s {
case "OK":
return OK
Expand All @@ -22,6 +22,7 @@ func StrToStatus(s string) Status {
}
panic("invalid inputs.")
}

// Parse parses <status>=<status> notation string. <status> is one of:
// - ok
// - warning
Expand All @@ -41,22 +42,22 @@ func Parse(arg string) (map[Status]Status, error) {
if s == "" {
continue
}
v := strings.Split(s, "=")
if len(v) != 2 {
return nil, fmt.Errorf("arguments is invalid : %v", v)
rawFrom, rawTo, found := strings.Cut(s, "=")
if !found {
return nil, fmt.Errorf("arguments is invalid : %v", s)
}
from := strings.ToUpper(v[0])
to := strings.ToUpper(v[1])
if !slices.Contains(Keywords, from) {
return nil, fmt.Errorf("from argument is invalid : %s", v[0])
from := strings.ToUpper(rawFrom)
to := strings.ToUpper(rawTo)
if !slices.Contains(keywords, from) {
return nil, fmt.Errorf("from argument is invalid : %s", rawFrom)
}
if !slices.Contains(Keywords, to) {
return nil, fmt.Errorf("to argument is invalid : %s", v[1])
if !slices.Contains(keywords, to) {
return nil, fmt.Errorf("to argument is invalid : %s", rawTo)
}
if _, ok := maps[StrToStatus(from)]; ok {
if _, ok := maps[strToStatus(from)]; ok {
return nil, fmt.Errorf("arguments is duplicate : %v", from)
}
maps[StrToStatus(from)] = StrToStatus(to)
maps[strToStatus(from)] = strToStatus(to)
}
return maps, nil
}

0 comments on commit cea26f1

Please sign in to comment.