-
Notifications
You must be signed in to change notification settings - Fork 0
/
uname.go
57 lines (48 loc) · 1.13 KB
/
uname.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package uname
import (
"syscall"
)
func charsToString(ca []int8) string {
s := make([]byte, len(ca))
var lens int
for ; lens < len(ca); lens++ {
if ca[lens] == 0 {
break
}
s[lens] = uint8(ca[lens])
}
return string(s[0:lens])
}
// Uname is wrapper for syscall uname
type Uname struct {
ub syscall.Utsname
}
// Init call uname syscall
func New() (*Uname, error) {
u := &Uname{}
err := syscall.Uname(&u.ub)
if err != nil {
return nil, err
}
return u, nil
}
// Machine return machine hardware name (like uname -m)
func (u *Uname) Machine() string {
return charsToString(u.ub.Machine[:])
}
// Sysname return operating system (like uname -s)
func (u *Uname) Sysname() string {
return charsToString(u.ub.Sysname[:])
}
// Nodename return network node hostname (like uname -n)
func (u *Uname) Nodename() string {
return charsToString(u.ub.Nodename[:])
}
// KernelRelease return kernel release (like uname -r)
func (u *Uname) KernelRelease() string {
return charsToString(u.ub.Release[:])
}
// KernelVersion return kernel version (like uname -v)
func (u *Uname) KernelVersion() string {
return charsToString(u.ub.Version[:])
}