1
2
3
4
5
6
7 package osinfo
8
9 import (
10 "strings"
11 "syscall"
12 )
13
14
15 func Version() (string, error) {
16 sysname, err := syscall.Sysctl("kern.ostype")
17 if err != nil {
18 return "", err
19 }
20 release, err := syscall.Sysctl("kern.osrelease")
21 if err != nil {
22 return "", err
23 }
24 version, err := syscall.Sysctl("kern.version")
25 if err != nil {
26 return "", err
27 }
28
29
30 version = strings.ReplaceAll(version, "\n", " ")
31 version = strings.ReplaceAll(version, "\t", " ")
32 version = strings.TrimSpace(version)
33
34 machine, err := syscall.Sysctl("hw.machine")
35 if err != nil {
36 return "", err
37 }
38
39 ret := sysname + " " + release + " " + version + " " + machine
40 return ret, nil
41 }
42
View as plain text