From 4524dcf51e0222193889e3945ff975962c5ab8a0 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 1 Apr 2020 08:49:25 -0700 Subject: [PATCH] version: move runtime.OS to tailscale OS mapping func to version So other code can use this without duplicating the policy. --- control/controlclient/direct.go | 17 +---------------- version/prop.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 826dcea4e..a8c8b460f 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -17,7 +17,6 @@ import ( "log" "net/http" "os" - "runtime" "strconv" "strings" "sync" @@ -140,26 +139,12 @@ func NewDirect(opts Options) (*Direct, error) { return c, nil } -func hostinfoOS() string { - os := runtime.GOOS - switch os { - case "darwin": - if version.IsMobile() { - return "iOS" - } else { - return "macOS" - } - default: - return os - } -} - func NewHostinfo() *tailcfg.Hostinfo { hostname, _ := os.Hostname() return &tailcfg.Hostinfo{ IPNVersion: version.LONG, Hostname: hostname, - OS: hostinfoOS(), + OS: version.OS(), } } diff --git a/version/prop.go b/version/prop.go index 1cbd8a6fc..f13aa8ff4 100644 --- a/version/prop.go +++ b/version/prop.go @@ -13,3 +13,15 @@ func IsMobile() bool { return runtime.GOOS == "android" || (runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64")) } + +// OS returns runtime.GOOS, except instead of returning "darwin" it +// returns "iOS" or "macOS". +func OS() string { + if runtime.GOOS == "darwin" { + if IsMobile() { + return "iOS" + } + return "macOS" + } + return runtime.GOOS +}