Browse Source

version: move runtime.OS to tailscale OS mapping func to version

So other code can use this without duplicating the policy.
Brad Fitzpatrick 6 years ago
parent
commit
4524dcf51e
2 changed files with 13 additions and 16 deletions
  1. 1 16
      control/controlclient/direct.go
  2. 12 0
      version/prop.go

+ 1 - 16
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(),
 	}
 }
 

+ 12 - 0
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
+}