Skip to content

Commit

Permalink
GetSemanticVersion is common to all OS
Browse files Browse the repository at this point in the history
  • Loading branch information
uaalto committed Aug 14, 2015
1 parent 9e4ea10 commit 028a967
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/github.com/getlantern/osversion/osversion.go
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
package osversion

import (
"github.com/blang/semver"
)

func GetSemanticVersion() (semver.Version, error) {
str, err := GetString()
if err != nil {
return semver.Version{}, err
}

return semver.Make(str)
}
19 changes: 6 additions & 13 deletions src/github.com/getlantern/osversion/osversion_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import "C"

import (
"errors"
"fmt"
"strconv"
"strings"
"unsafe"

"github.com/blang/semver"
)

func GetString() (string, error) {
Expand All @@ -29,20 +28,11 @@ func GetString() (string, error) {

err := C.darwin_get_os(str, bufferSize)
if err == -1 {
return "", errors.New("Error running sysctl")
return "", errors.New(fmt.Sprintf("Error running sysctl: %v", err))
}
return C.GoString(str), nil
}

func GetSemanticVersion() (semver.Version, error) {
str, err := GetString()
if err != nil {
return semver.Version{}, err
}

return semver.Make(str)
}

func GetHumanReadable() (string, error) {
versions := []string{
"OS X 10.0.{patch} Cheetah",
Expand All @@ -63,8 +53,11 @@ func GetHumanReadable() (string, error) {
if err != nil {
return "", err
}
if version.Major < 4 || version.Major > 11 {
return "", errors.New("Unknown OS X version")
}

return strings.Replace(versions[version.Major - 4],
return strings.Replace(versions[version.Major-4],
"{patch}",
strconv.FormatUint(version.Patch, 10),
1), nil
Expand Down

0 comments on commit 028a967

Please sign in to comment.