From eaaa793b6351caf7b7f30fcc8a88e9b5b6b594e0 Mon Sep 17 00:00:00 2001 From: Yakiyo Date: Mon, 28 Aug 2023 15:27:55 +0000 Subject: [PATCH] refactor: move safeplatform in diff func and use lo for valid --- utils/platform.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/platform.go b/utils/platform.go index 8989c17..66b31cd 100644 --- a/utils/platform.go +++ b/utils/platform.go @@ -3,6 +3,8 @@ package utils import ( "runtime" "strings" + + "github.com/samber/lo" ) // Get current platform name. Return common if unknown (shouldnt generally occur) @@ -22,16 +24,16 @@ func Platform() string { var VALID_PLATFORMS = []string{"windows", "linux", "osx", "android", "sunos"} // check if a platform is valid or not -func ValidPlatform(plat string) bool { +func IsValidPlatform(plat string) bool { + return lo.Contains(VALID_PLATFORMS, plat) +} + +// convert plat to app friendly type +func SafePlatform(plat string) string { plat = strings.ToLower(plat) switch plat { case "darwin", "macos": plat = "osx" } - for _, x := range VALID_PLATFORMS { - if plat == x { - return true - } - } - return false + return plat }