-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package version | ||
|
||
func GetVersion() string { | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
func getString(input [65]int8) string { | ||
var buf [65]byte | ||
for i, b := range input { | ||
buf[i] = byte(b) | ||
} | ||
ver := string(buf[:]) | ||
if i := strings.Index(ver, "\x00"); i != -1 { | ||
ver = ver[:i] | ||
} | ||
return ver | ||
} | ||
|
||
// GetVersion returns the os version information | ||
func GetVersion() string { | ||
var uname syscall.Utsname | ||
if err := syscall.Uname(&uname); err != nil { | ||
log.Fatal(err) | ||
} | ||
return fmt.Sprintf("%s %s %s", getString(uname.Sysname), getString(uname.Nodename), getString(uname.Release)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
type osVersionInfoEx struct { | ||
osVersionInfoSize uint32 | ||
major uint32 | ||
minor uint32 | ||
build uint32 | ||
platformID uint32 | ||
csdVersion [128]uint16 | ||
servicePackMajor uint16 | ||
servicePackMinor uint16 | ||
suiteMask uint16 | ||
productType byte | ||
wReserved byte | ||
} | ||
|
||
func GetVersion() string { | ||
kernel32 := syscall.MustLoadDLL("ntdll.dll") | ||
procGetProductInfo := kernel32.MustFindProc("RtlGetVersion") | ||
osVersion := osVersionInfoEx{} | ||
osVersion.osVersionInfoSize = uint32(unsafe.Sizeof(osVersion)) | ||
r1, _, err := procGetProductInfo.Call(uintptr(unsafe.Pointer(&osVersion))) | ||
if r1 != 0 { | ||
log.Fatal(err) | ||
} | ||
return fmt.Sprintf("%d.%d build %d", osVersion.major, osVersion.minor, osVersion.build) | ||
} |