From cea26f18f91e146219be49182b5b250949eb4e4c Mon Sep 17 00:00:00 2001 From: yseto Date: Wed, 27 Sep 2023 18:57:33 +0900 Subject: [PATCH] fix to private scope --- asstatusparse.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/asstatusparse.go b/asstatusparse.go index 6f62320..6648833 100644 --- a/asstatusparse.go +++ b/asstatusparse.go @@ -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 @@ -22,6 +22,7 @@ func StrToStatus(s string) Status { } panic("invalid inputs.") } + // Parse parses = notation string. is one of: // - ok // - warning @@ -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 }