Skip to content

Commit

Permalink
refactor: move safeplatform in diff func and use lo for valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakiyo committed Aug 28, 2023
1 parent 5ee4d45 commit eaaa793
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions utils/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package utils
import (
"runtime"
"strings"

"github.com/samber/lo"
)

// Get current platform name. Return common if unknown (shouldnt generally occur)
Expand All @@ -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
}

0 comments on commit eaaa793

Please # to comment.