diff --git a/_tools/v3migration/v3migration.go b/_tools/v3migration/v3migration.go index 53ee6e8..eb826f4 100644 --- a/_tools/v3migration/v3migration.go +++ b/_tools/v3migration/v3migration.go @@ -103,5 +103,4 @@ func main() { issueRemoveUnusedValue() } } - } diff --git a/cpu/cpu.go b/cpu/cpu.go index caf4d46..411a063 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -51,8 +51,10 @@ type lastPercent struct { lastPerCPUTimes []TimesStat } -var lastCPUPercent lastPercent -var invoke common.Invoker = common.Invoke{} +var ( + lastCPUPercent lastPercent + invoke common.Invoker = common.Invoke{} +) func init() { lastCPUPercent.Lock() diff --git a/cpu/cpu_aix.go b/cpu/cpu_aix.go index 28b61c2..8f35bdc 100644 --- a/cpu/cpu_aix.go +++ b/cpu/cpu_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package cpu diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index 9f3988b..7acb258 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package cpu diff --git a/cpu/cpu_darwin_cgo.go b/cpu/cpu_darwin_cgo.go index 2a7d4a1..1d5f077 100644 --- a/cpu/cpu_darwin_cgo.go +++ b/cpu/cpu_darwin_cgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build cgo +//go:build darwin && cgo +// +build darwin,cgo package cpu @@ -108,5 +108,4 @@ func allCPUTimes() ([]TimesStat, error) { } return []TimesStat{c}, nil - } diff --git a/cpu/cpu_darwin_nocgo.go b/cpu/cpu_darwin_nocgo.go index 3eaaf88..e067e99 100644 --- a/cpu/cpu_darwin_nocgo.go +++ b/cpu/cpu_darwin_nocgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build !cgo +//go:build darwin && !cgo +// +build darwin,!cgo package cpu diff --git a/cpu/cpu_dragonfly.go b/cpu/cpu_dragonfly.go index a9c81cc..fef53e5 100644 --- a/cpu/cpu_dragonfly.go +++ b/cpu/cpu_dragonfly.go @@ -15,14 +15,16 @@ import ( "golang.org/x/sys/unix" ) -var ClocksPerSec = float64(128) -var cpuMatch = regexp.MustCompile(`^CPU:`) -var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) -var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) -var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) -var cpuEnd = regexp.MustCompile(`^Trying to mount root`) -var cpuTimesSize int -var emptyTimes cpuTimes +var ( + ClocksPerSec = float64(128) + cpuMatch = regexp.MustCompile(`^CPU:`) + originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) + featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) + featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) + cpuEnd = regexp.MustCompile(`^Trying to mount root`) + cpuTimesSize int + emptyTimes cpuTimes +) func init() { clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) diff --git a/cpu/cpu_fallback.go b/cpu/cpu_fallback.go index 5f0440b..6d7007f 100644 --- a/cpu/cpu_fallback.go +++ b/cpu/cpu_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !dragonfly && !plan9 && !aix // +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix package cpu diff --git a/cpu/cpu_freebsd.go b/cpu/cpu_freebsd.go index 3b83cf3..d3f4735 100644 --- a/cpu/cpu_freebsd.go +++ b/cpu/cpu_freebsd.go @@ -15,15 +15,17 @@ import ( "golang.org/x/sys/unix" ) -var ClocksPerSec = float64(128) -var cpuMatch = regexp.MustCompile(`^CPU:`) -var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) -var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) -var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) -var cpuEnd = regexp.MustCompile(`^Trying to mount root`) -var cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`) -var cpuTimesSize int -var emptyTimes cpuTimes +var ( + ClocksPerSec = float64(128) + cpuMatch = regexp.MustCompile(`^CPU:`) + originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) + featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) + featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) + cpuEnd = regexp.MustCompile(`^Trying to mount root`) + cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`) + cpuTimesSize int + emptyTimes cpuTimes +) func init() { clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) diff --git a/cpu/cpu_freebsd_test.go b/cpu/cpu_freebsd_test.go index 39c80eb..27a709d 100644 --- a/cpu/cpu_freebsd_test.go +++ b/cpu/cpu_freebsd_test.go @@ -13,7 +13,7 @@ func TestParseDmesgBoot(t *testing.T) { t.SkipNow() } - var cpuTests = []struct { + cpuTests := []struct { file string cpuNum int cores int32 diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 563a78e..4f26230 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package cpu @@ -30,7 +31,7 @@ func Times(percpu bool) ([]TimesStat, error) { func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { filename := common.HostProc("stat") - var lines = []string{} + lines := []string{} if percpu { statlines, err := common.ReadLines(filename) if err != nil || len(statlines) < 2 { @@ -338,7 +339,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) { } // physical cores // https://github.com/giampaolo/psutil/blob/8415355c8badc9c94418b19bdf26e622f06f0cce/psutil/_pslinux.py#L615-L628 - var threadSiblingsLists = make(map[string]bool) + threadSiblingsLists := make(map[string]bool) // These 2 files are the same but */core_cpus_list is newer while */thread_siblings_list is deprecated and may disappear in the future. // https://www.kernel.org/doc/Documentation/admin-guide/cputopology.rst // https://github.com/giampaolo/psutil/pull/1727#issuecomment-707624964 diff --git a/cpu/cpu_openbsd.go b/cpu/cpu_openbsd.go index 8eb28db..701d45c 100644 --- a/cpu/cpu_openbsd.go +++ b/cpu/cpu_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package cpu @@ -108,7 +109,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { j *= 2 } - var cpuTimes = make([]int32, cpUStates) + cpuTimes := make([]int32, cpUStates) var mib []int32 if percpu { mib = []int32{ctlKern, kernCptime2, int32(j)} diff --git a/cpu/cpu_plan9.go b/cpu/cpu_plan9.go index 1729b85..a2e99d8 100644 --- a/cpu/cpu_plan9.go +++ b/cpu/cpu_plan9.go @@ -1,3 +1,4 @@ +//go:build plan9 // +build plan9 package cpu diff --git a/cpu/cpu_plan9_test.go b/cpu/cpu_plan9_test.go index 4f585f9..9acf4bf 100644 --- a/cpu/cpu_plan9_test.go +++ b/cpu/cpu_plan9_test.go @@ -1,3 +1,4 @@ +//go:build plan9 // +build plan9 package cpu diff --git a/cpu/cpu_solaris.go b/cpu/cpu_solaris.go index 4e3dea0..b5ee70f 100644 --- a/cpu/cpu_solaris.go +++ b/cpu/cpu_solaris.go @@ -24,7 +24,7 @@ func init() { } } -//sum all values in a float64 map with float64 keys +// sum all values in a float64 map with float64 keys func msum(x map[float64]float64) float64 { total := 0.0 for _, y := range x { @@ -47,7 +47,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { user := make(map[float64]float64) kern := make(map[float64]float64) iowt := make(map[float64]float64) - //swap := make(map[float64]float64) + // swap := make(map[float64]float64) kstatSysOut, err := invoke.CommandWithContext(ctx, kstatSys, "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/") if err != nil { return nil, fmt.Errorf("cannot execute kstat: %s", err) diff --git a/cpu/cpu_solaris_test.go b/cpu/cpu_solaris_test.go index 6b1ca6e..508aad5 100644 --- a/cpu/cpu_solaris_test.go +++ b/cpu/cpu_solaris_test.go @@ -15,28 +15,36 @@ func TestParseISAInfo(t *testing.T) { }{ { "1cpu_1core_isainfo.txt", - []string{"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", + []string{ + "rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", "avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", - "tsc", "fpu"}, + "tsc", "fpu", + }, }, { "2cpu_1core_isainfo.txt", - []string{"rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", + []string{ + "rdseed", "adx", "avx2", "fma", "bmi2", "bmi1", "rdrand", "f16c", "vmx", "avx", "xsave", "pclmulqdq", "aes", "movbe", "sse4.2", "sse4.1", "ssse3", "popcnt", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", - "tsc", "fpu"}, + "tsc", "fpu", + }, }, { "2cpu_8core_isainfo.txt", - []string{"vmx", "avx", "xsave", "pclmulqdq", "aes", "sse4.2", "sse4.1", "ssse3", "popcnt", + []string{ + "vmx", "avx", "xsave", "pclmulqdq", "aes", "sse4.2", "sse4.1", "ssse3", "popcnt", "tscp", "cx16", "sse3", "sse2", "sse", "fxsr", "mmx", "cmov", "amd_sysc", "cx8", - "tsc", "fpu"}, + "tsc", "fpu", + }, }, { "2cpu_12core_isainfo.txt", - []string{"amd_svm", "amd_lzcnt", "popcnt", "amd_sse4a", "tscp", "ahf", "cx16", "sse3", "sse2", - "sse", "fxsr", "amd_3dnowx", "amd_3dnow", "amd_mmx", "mmx", "cmov", "amd_sysc", "cx8", "tsc", "fpu"}, + []string{ + "amd_svm", "amd_lzcnt", "popcnt", "amd_sse4a", "tscp", "ahf", "cx16", "sse3", "sse2", + "sse", "fxsr", "amd_3dnowx", "amd_3dnow", "amd_mmx", "mmx", "cmov", "amd_sysc", "cx8", "tsc", "fpu", + }, }, } diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index 66390b7..91b8e8a 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -74,7 +74,6 @@ func TestCpu_times(t *testing.T) { if cpuTotal[0].Idle != 0 { assert.InEpsilon(t, cpuTotal[0].Idle, perCPUIdleTimeSum, margin) } - } func TestCpu_counts(t *testing.T) { @@ -162,7 +161,6 @@ func testCPUPercent(t *testing.T, percpu bool) { } func testCPUPercentLastUsed(t *testing.T, percpu bool) { - numcpu := runtime.NumCPU() testCount := 10 @@ -194,7 +192,6 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) { } } } - } func TestCPUPercent(t *testing.T) { diff --git a/cpu/cpu_windows.go b/cpu/cpu_windows.go index 1808eb8..d1a0e4c 100644 --- a/cpu/cpu_windows.go +++ b/cpu/cpu_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package cpu diff --git a/disk/disk_aix.go b/disk/disk_aix.go index a9cdc81..e37686b 100644 --- a/disk/disk_aix.go +++ b/disk/disk_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package disk @@ -13,10 +14,12 @@ import ( var FSType map[int]string func init() { - FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", + FSType = map[int]string{ + 0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", 16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs", 33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs", - 39: "ahafs", 40: "sterm-nfs", 41: "asmfs"} + 39: "ahafs", 40: "sterm-nfs", 41: "asmfs", + } } func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { diff --git a/disk/disk_darwin.go b/disk/disk_darwin.go index 985e9f3..0877b76 100644 --- a/disk/disk_darwin.go +++ b/disk/disk_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package disk diff --git a/disk/disk_darwin_cgo.go b/disk/disk_darwin_cgo.go index 8551c2f..b041c8d 100644 --- a/disk/disk_darwin_cgo.go +++ b/disk/disk_darwin_cgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build cgo +//go:build darwin && cgo +// +build darwin,cgo package disk diff --git a/disk/disk_darwin_nocgo.go b/disk/disk_darwin_nocgo.go index a118be8..99bb8ba 100644 --- a/disk/disk_darwin_nocgo.go +++ b/disk/disk_darwin_nocgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build !cgo +//go:build darwin && !cgo +// +build darwin,!cgo package disk diff --git a/disk/disk_fallback.go b/disk/disk_fallback.go index 4bb4633..4768733 100644 --- a/disk/disk_fallback.go +++ b/disk/disk_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix // +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix package disk diff --git a/disk/disk_freebsd.go b/disk/disk_freebsd.go index 767a28b..e74c186 100644 --- a/disk/disk_freebsd.go +++ b/disk/disk_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package disk diff --git a/disk/disk_freebsd_386.go b/disk/disk_freebsd_386.go index 9fc7cb2..7fa1783 100644 --- a/disk/disk_freebsd_386.go +++ b/disk/disk_freebsd_386.go @@ -52,6 +52,7 @@ type devstat struct { Id *byte Sequence1 uint32 } + type bintime struct { Sec int32 Frac uint64 diff --git a/disk/disk_freebsd_amd64.go b/disk/disk_freebsd_amd64.go index ffafc8f..d86a308 100644 --- a/disk/disk_freebsd_amd64.go +++ b/disk/disk_freebsd_amd64.go @@ -55,6 +55,7 @@ type devstat struct { Sequence1 uint32 Pad_cgo_2 [4]byte } + type bintime struct { Sec int64 Frac uint64 diff --git a/disk/disk_freebsd_arm.go b/disk/disk_freebsd_arm.go index 9fc7cb2..7fa1783 100644 --- a/disk/disk_freebsd_arm.go +++ b/disk/disk_freebsd_arm.go @@ -52,6 +52,7 @@ type devstat struct { Id *byte Sequence1 uint32 } + type bintime struct { Sec int32 Frac uint64 diff --git a/disk/disk_freebsd_arm64.go b/disk/disk_freebsd_arm64.go index a391217..f6b3f80 100644 --- a/disk/disk_freebsd_arm64.go +++ b/disk/disk_freebsd_arm64.go @@ -1,5 +1,6 @@ -// +build freebsd -// +build arm64 +//go:build freebsd && arm64 +// +build freebsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs disk/types_freebsd.go diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 6d98c18..24337d0 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package disk @@ -21,6 +22,7 @@ import ( const ( sectorSize = 512 ) + const ( // man statfs ADFS_SUPER_MAGIC = 0xadf5 diff --git a/disk/disk_openbsd.go b/disk/disk_openbsd.go index 24324a4..e065865 100644 --- a/disk/disk_openbsd.go +++ b/disk/disk_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package disk diff --git a/disk/disk_openbsd_386.go b/disk/disk_openbsd_386.go index 68f4e04..f4c139f 100644 --- a/disk/disk_openbsd_386.go +++ b/disk/disk_openbsd_386.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build 386 +//go:build openbsd && 386 +// +build openbsd,386 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs disk/types_openbsd.go diff --git a/disk/disk_openbsd_arm64.go b/disk/disk_openbsd_arm64.go index ff7b3e4..ae1cf57 100644 --- a/disk/disk_openbsd_arm64.go +++ b/disk/disk_openbsd_arm64.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build arm64 +//go:build openbsd && arm64 +// +build openbsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs disk/types_openbsd.go diff --git a/disk/disk_solaris.go b/disk/disk_solaris.go index 63c62d1..126a9e1 100644 --- a/disk/disk_solaris.go +++ b/disk/disk_solaris.go @@ -1,3 +1,4 @@ +//go:build solaris // +build solaris package disk @@ -23,20 +24,18 @@ const ( _MNTTAB = "/etc/mnttab" ) -var ( - // A blacklist of read-only virtual filesystems. Writable filesystems are of - // operational concern and must not be included in this list. - fsTypeBlacklist = map[string]struct{}{ - "ctfs": {}, - "dev": {}, - "fd": {}, - "lofs": {}, - "lxproc": {}, - "mntfs": {}, - "objfs": {}, - "proc": {}, - } -) +// A blacklist of read-only virtual filesystems. Writable filesystems are of +// operational concern and must not be included in this list. +var fsTypeBlacklist = map[string]struct{}{ + "ctfs": {}, + "dev": {}, + "fd": {}, + "lofs": {}, + "lxproc": {}, + "mntfs": {}, + "objfs": {}, + "proc": {}, +} func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS) @@ -113,6 +112,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { return usageStat, nil } + func SerialNumberWithContext(ctx context.Context, name string) (string, error) { return "", common.ErrNotImplementedError } diff --git a/disk/disk_unix.go b/disk/disk_unix.go index 9ca3bb3..bdb62b2 100644 --- a/disk/disk_unix.go +++ b/disk/disk_unix.go @@ -1,3 +1,4 @@ +//go:build freebsd || linux || darwin // +build freebsd linux darwin package disk diff --git a/disk/disk_windows.go b/disk/disk_windows.go index 1293586..9106364 100644 --- a/disk/disk_windows.go +++ b/disk/disk_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package disk @@ -106,7 +107,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro uintptr(len(lpFileSystemNameBuffer))) if driveret == 0 { if typeret == 5 || typeret == 2 { - continue //device is not ready will happen if there is no disk in the drive + continue // device is not ready will happen if there is no disk in the drive } return ret, err } diff --git a/disk/types_freebsd.go b/disk/types_freebsd.go index c617e85..47f5551 100644 --- a/disk/types_freebsd.go +++ b/disk/types_freebsd.go @@ -1,4 +1,6 @@ +//go:build ignore // +build ignore + // Hand writing: _Ctype_struct___0 /* @@ -58,5 +60,7 @@ type ( _C_long_double C.longlong ) -type devstat C.struct_devstat -type bintime C.struct_bintime +type ( + devstat C.struct_devstat + bintime C.struct_bintime +) diff --git a/disk/types_openbsd.go b/disk/types_openbsd.go index 7709aad..abb43c8 100644 --- a/disk/types_openbsd.go +++ b/disk/types_openbsd.go @@ -1,4 +1,6 @@ +//go:build ignore // +build ignore + // Hand writing: _Ctype_struct___0 /* @@ -25,8 +27,12 @@ const ( sizeOfDiskstats = C.sizeof_struct_diskstats ) -type Diskstats C.struct_diskstats -type Timeval C.struct_timeval +type ( + Diskstats C.struct_diskstats + Timeval C.struct_timeval +) -type Diskstat C.struct_diskstat -type bintime C.struct_bintime +type ( + Diskstat C.struct_diskstat + bintime C.struct_bintime +) diff --git a/docker/docker.go b/docker/docker.go index b139d86..dda7ba0 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -8,8 +8,10 @@ import ( "github.com/shirou/gopsutil/v3/internal/common" ) -var ErrDockerNotAvailable = errors.New("docker not available") -var ErrCgroupNotAvailable = errors.New("cgroup not available") +var ( + ErrDockerNotAvailable = errors.New("docker not available") + ErrCgroupNotAvailable = errors.New("cgroup not available") +) var invoke common.Invoker = common.Invoke{} diff --git a/docker/docker_linux.go b/docker/docker_linux.go index 650f7a2..0c07312 100644 --- a/docker/docker_linux.go +++ b/docker/docker_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package docker diff --git a/docker/docker_linux_test.go b/docker/docker_linux_test.go index bd5b8c7..c6afb44 100644 --- a/docker/docker_linux_test.go +++ b/docker/docker_linux_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package docker diff --git a/docker/docker_notlinux.go b/docker/docker_notlinux.go index 8df6a7c..df33512 100644 --- a/docker/docker_notlinux.go +++ b/docker/docker_notlinux.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package docker diff --git a/host/host_bsd.go b/host/host_bsd.go index fc45b87..4dc2bba 100644 --- a/host/host_bsd.go +++ b/host/host_bsd.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || openbsd // +build darwin freebsd openbsd package host diff --git a/host/host_darwin.go b/host/host_darwin.go index 6ac7a82..575a08b 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package host @@ -94,7 +95,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } return ret, nil - } func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { diff --git a/host/host_darwin_386.go b/host/host_darwin_386.go index c3596f9..8caeed2 100644 --- a/host/host_darwin_386.go +++ b/host/host_darwin_386.go @@ -14,6 +14,7 @@ type Utmpx struct { Host [256]int8 Pad [16]uint32 } + type Timeval struct { Sec int32 } diff --git a/host/host_darwin_amd64.go b/host/host_darwin_amd64.go index c3596f9..8caeed2 100644 --- a/host/host_darwin_amd64.go +++ b/host/host_darwin_amd64.go @@ -14,6 +14,7 @@ type Utmpx struct { Host [256]int8 Pad [16]uint32 } + type Timeval struct { Sec int32 } diff --git a/host/host_darwin_arm64.go b/host/host_darwin_arm64.go index 74c28f2..293bd4d 100644 --- a/host/host_darwin_arm64.go +++ b/host/host_darwin_arm64.go @@ -1,5 +1,6 @@ -// +build darwin -// +build arm64 +//go:build darwin && arm64 +// +build darwin,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs host/types_darwin.go diff --git a/host/host_darwin_cgo.go b/host/host_darwin_cgo.go index 5c06d90..ffdc7b7 100644 --- a/host/host_darwin_cgo.go +++ b/host/host_darwin_cgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build cgo +//go:build darwin && cgo +// +build darwin,cgo package host diff --git a/host/host_darwin_nocgo.go b/host/host_darwin_nocgo.go index 96d80d7..6285ba9 100644 --- a/host/host_darwin_nocgo.go +++ b/host/host_darwin_nocgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build !cgo +//go:build darwin && !cgo +// +build darwin,!cgo package host diff --git a/host/host_fallback.go b/host/host_fallback.go index 35b5537..585250f 100644 --- a/host/host_fallback.go +++ b/host/host_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows // +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows package host diff --git a/host/host_freebsd.go b/host/host_freebsd.go index d7efd69..2c9aa9d 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package host @@ -81,7 +82,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } return ret, nil - } func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { diff --git a/host/host_freebsd_arm64.go b/host/host_freebsd_arm64.go index 1cb8631..41bec3c 100644 --- a/host/host_freebsd_arm64.go +++ b/host/host_freebsd_arm64.go @@ -1,5 +1,6 @@ -// +build freebsd -// +build arm64 +//go:build freebsd && arm64 +// +build freebsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs host/types_freebsd.go diff --git a/host/host_linux.go b/host/host_linux.go index e7c9e0d..29ad9ab 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package host @@ -121,7 +122,6 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } return ret, nil - } func getlsbStruct() (*lsbStruct, error) { @@ -304,7 +304,6 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil } return platform, family, version, nil - } func KernelVersionWithContext(ctx context.Context) (version string, err error) { diff --git a/host/host_linux_386.go b/host/host_linux_386.go index 79b5cb5..46e0c5d 100644 --- a/host/host_linux_386.go +++ b/host/host_linux_386.go @@ -35,10 +35,12 @@ type utmp struct { Addr_v6 [4]int32 X__unused [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type UtTv struct { Sec int32 Usec int32 diff --git a/host/host_linux_amd64.go b/host/host_linux_amd64.go index 9a69652..1e57448 100644 --- a/host/host_linux_amd64.go +++ b/host/host_linux_amd64.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int64 Usec int64 diff --git a/host/host_linux_arm.go b/host/host_linux_arm.go index e2cf448..7abbbb8 100644 --- a/host/host_linux_arm.go +++ b/host/host_linux_arm.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int32 Usec int32 diff --git a/host/host_linux_arm64.go b/host/host_linux_arm64.go index 37dbe5c..eebef55 100644 --- a/host/host_linux_arm64.go +++ b/host/host_linux_arm64.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int64 Usec int64 diff --git a/host/host_linux_mips.go b/host/host_linux_mips.go index b0fca09..50207e5 100644 --- a/host/host_linux_mips.go +++ b/host/host_linux_mips.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__unused [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int32 Usec int32 diff --git a/host/host_linux_mips64.go b/host/host_linux_mips64.go index b0fca09..50207e5 100644 --- a/host/host_linux_mips64.go +++ b/host/host_linux_mips64.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__unused [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int32 Usec int32 diff --git a/host/host_linux_mips64le.go b/host/host_linux_mips64le.go index b0fca09..50207e5 100644 --- a/host/host_linux_mips64le.go +++ b/host/host_linux_mips64le.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__unused [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int32 Usec int32 diff --git a/host/host_linux_mipsle.go b/host/host_linux_mipsle.go index b0fca09..50207e5 100644 --- a/host/host_linux_mipsle.go +++ b/host/host_linux_mipsle.go @@ -33,10 +33,12 @@ type utmp struct { Addr_v6 [4]int32 X__unused [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int32 Usec int32 diff --git a/host/host_linux_ppc64le.go b/host/host_linux_ppc64le.go index d081a08..51f5bee 100644 --- a/host/host_linux_ppc64le.go +++ b/host/host_linux_ppc64le.go @@ -1,5 +1,6 @@ -// +build linux -// +build ppc64le +//go:build linux && ppc64le +// +build linux,ppc64le + // Created by cgo -godefs - DO NOT EDIT // cgo -godefs types_linux.go @@ -35,10 +36,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int64 Usec int64 diff --git a/host/host_linux_riscv64.go b/host/host_linux_riscv64.go index 79a077d..bb03a0b 100644 --- a/host/host_linux_riscv64.go +++ b/host/host_linux_riscv64.go @@ -32,10 +32,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]uint8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int64 Usec int64 diff --git a/host/host_linux_s390x.go b/host/host_linux_s390x.go index 083fbf9..6ea432a 100644 --- a/host/host_linux_s390x.go +++ b/host/host_linux_s390x.go @@ -1,5 +1,6 @@ -// +build linux -// +build s390x +//go:build linux && s390x +// +build linux,s390x + // Created by cgo -godefs - DO NOT EDIT // cgo -godefs types_linux.go @@ -35,10 +36,12 @@ type utmp struct { Addr_v6 [4]int32 X__glibc_reserved [20]int8 } + type exit_status struct { Termination int16 Exit int16 } + type timeval struct { Sec int64 Usec int64 diff --git a/host/host_linux_test.go b/host/host_linux_test.go index 7808eee..8c23e56 100644 --- a/host/host_linux_test.go +++ b/host/host_linux_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package host diff --git a/host/host_openbsd.go b/host/host_openbsd.go index 7e982ff..569de4a 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package host diff --git a/host/host_openbsd_386.go b/host/host_openbsd_386.go index af0d855..b299d7a 100644 --- a/host/host_openbsd_386.go +++ b/host/host_openbsd_386.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build 386 +//go:build openbsd && 386 +// +build openbsd,386 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs host/types_openbsd.go diff --git a/host/host_openbsd_amd64.go b/host/host_openbsd_amd64.go index afe0943..2d23b9b 100644 --- a/host/host_openbsd_amd64.go +++ b/host/host_openbsd_amd64.go @@ -25,6 +25,7 @@ type Utmp struct { Host [256]int8 Time int64 } + type Timeval struct { Sec int64 Usec int64 diff --git a/host/host_openbsd_arm64.go b/host/host_openbsd_arm64.go index 3efc44e..20fb42d 100644 --- a/host/host_openbsd_arm64.go +++ b/host/host_openbsd_arm64.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build arm64 +//go:build openbsd && arm64 +// +build openbsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs host/types_openbsd.go diff --git a/host/host_posix.go b/host/host_posix.go index 1cdf16d..89e6378 100644 --- a/host/host_posix.go +++ b/host/host_posix.go @@ -1,3 +1,4 @@ +//go:build linux || freebsd || openbsd || darwin || solaris // +build linux freebsd openbsd darwin solaris package host diff --git a/host/host_windows.go b/host/host_windows.go index 0ab5e76..fcd1d59 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package host diff --git a/host/types_darwin.go b/host/types_darwin.go index b858227..3378cff 100644 --- a/host/types_darwin.go +++ b/host/types_darwin.go @@ -1,4 +1,6 @@ +//go:build ignore // +build ignore + // plus hand editing about timeval /* @@ -13,5 +15,7 @@ package host */ import "C" -type Utmpx C.struct_utmpx -type Timeval C.struct_timeval +type ( + Utmpx C.struct_utmpx + Timeval C.struct_timeval +) diff --git a/host/types_freebsd.go b/host/types_freebsd.go index bbdce0c..79154d7 100644 --- a/host/types_freebsd.go +++ b/host/types_freebsd.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore /* @@ -40,5 +41,7 @@ type ( _C_long_long C.longlong ) -type Utmp C.struct_utmp // for FreeBSD 9.0 compatibility -type Utmpx C.struct_futx +type ( + Utmp C.struct_utmp // for FreeBSD 9.0 compatibility + Utmpx C.struct_futx +) diff --git a/host/types_linux.go b/host/types_linux.go index 8adecb6..2b087b1 100644 --- a/host/types_linux.go +++ b/host/types_linux.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore /* @@ -37,6 +38,8 @@ type ( _C_long_long C.longlong ) -type utmp C.struct_utmp -type exit_status C.struct_exit_status -type timeval C.struct_timeval +type ( + utmp C.struct_utmp + exit_status C.struct_exit_status + timeval C.struct_timeval +) diff --git a/host/types_openbsd.go b/host/types_openbsd.go index 9ebb97c..81cdd53 100644 --- a/host/types_openbsd.go +++ b/host/types_openbsd.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore /* @@ -39,5 +40,7 @@ type ( _C_long_long C.longlong ) -type Utmp C.struct_utmp -type Timeval C.struct_timeval +type ( + Utmp C.struct_utmp + Timeval C.struct_timeval +) diff --git a/internal/common/binary.go b/internal/common/binary.go index 9b5dc55..446c359 100644 --- a/internal/common/binary.go +++ b/internal/common/binary.go @@ -388,8 +388,10 @@ type coder struct { buf []byte } -type decoder coder -type encoder coder +type ( + decoder coder + encoder coder +) func (d *decoder) uint8() uint8 { x := d.buf[0] diff --git a/internal/common/common.go b/internal/common/common.go index 8f57a79..435b8d5 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -98,7 +98,6 @@ var ErrNotImplementedError = errors.New("not implemented yet") // ReadFile reads contents from a file func ReadFile(filename string) (string, error) { content, err := ioutil.ReadFile(filename) - if err != nil { return "", err } @@ -312,7 +311,7 @@ func PathExists(filename string) bool { return false } -//GetEnv retrieves the environment variable key. If it does not exist it returns the default. +// GetEnv retrieves the environment variable key. If it does not exist it returns the default. func GetEnv(key string, dfault string, combineWith ...string) string { value := os.Getenv(key) if value == "" { diff --git a/internal/common/common_darwin.go b/internal/common/common_darwin.go index be46af3..3b2b8e0 100644 --- a/internal/common/common_darwin.go +++ b/internal/common/common_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package common diff --git a/internal/common/common_freebsd.go b/internal/common/common_freebsd.go index 85bda0e..2510f9d 100644 --- a/internal/common/common_freebsd.go +++ b/internal/common/common_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd || openbsd // +build freebsd openbsd package common diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 7349989..6d44ce4 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package common @@ -55,7 +56,6 @@ func NumProcs() (uint64, error) { } func BootTimeWithContext(ctx context.Context) (uint64, error) { - system, role, err := Virtualization() if err != nil { return 0, err @@ -201,7 +201,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) { if PathExists(filepath.Join(filename, "self", "status")) { contents, err := ReadLines(filepath.Join(filename, "self", "status")) if err == nil { - if StringsContains(contents, "s_context:") || StringsContains(contents, "VxID:") { system = "linux-vserver" diff --git a/internal/common/common_openbsd.go b/internal/common/common_openbsd.go index ba73a7e..cbd3d28 100644 --- a/internal/common/common_openbsd.go +++ b/internal/common/common_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package common diff --git a/internal/common/common_test.go b/internal/common/common_test.go index b0e051c..93f33ec 100644 --- a/internal/common/common_test.go +++ b/internal/common/common_test.go @@ -37,6 +37,7 @@ func TestIntToString(t *testing.T) { t.Error("could not convert") } } + func TestByteToString(t *testing.T) { src := []byte{65, 66, 67} dst := ByteToString(src) @@ -63,12 +64,14 @@ func TestMustParseInt32(t *testing.T) { t.Error("could not parse") } } + func TestMustParseUint64(t *testing.T) { ret := mustParseUint64("11111") if ret != uint64(11111) { t.Error("could not parse") } } + func TestMustParseFloat64(t *testing.T) { ret := mustParseFloat64("11111.11") if ret != float64(11111.11) { @@ -79,6 +82,7 @@ func TestMustParseFloat64(t *testing.T) { t.Error("could not parse") } } + func TestStringsContains(t *testing.T) { target, err := ReadLines("common_test.go") if err != nil { diff --git a/internal/common/common_unix.go b/internal/common/common_unix.go index 6052028..a4a953a 100644 --- a/internal/common/common_unix.go +++ b/internal/common/common_unix.go @@ -1,3 +1,4 @@ +//go:build linux || freebsd || darwin || openbsd // +build linux freebsd darwin openbsd package common diff --git a/internal/common/common_windows.go b/internal/common/common_windows.go index ba20136..295b70b 100644 --- a/internal/common/common_windows.go +++ b/internal/common/common_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package common @@ -162,7 +163,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance if err != nil { return nil, err } - var counter = Win32PerformanceCounter{ + counter := Win32PerformanceCounter{ Query: query, PostName: postName, CounterName: counterName, diff --git a/internal/common/sleep.go b/internal/common/sleep.go index ee27e54..8c35b17 100644 --- a/internal/common/sleep.go +++ b/internal/common/sleep.go @@ -8,7 +8,7 @@ import ( // Sleep awaits for provided interval. // Can be interrupted by context cancelation. func Sleep(ctx context.Context, interval time.Duration) error { - var timer = time.NewTimer(interval) + timer := time.NewTimer(interval) select { case <-ctx.Done(): return ctx.Err() diff --git a/internal/common/sleep_test.go b/internal/common/sleep_test.go index 2c846db..aadc766 100644 --- a/internal/common/sleep_test.go +++ b/internal/common/sleep_test.go @@ -11,17 +11,17 @@ import ( func TestSleep(test *testing.T) { const dt = 50 * time.Millisecond - var t = func(name string, ctx context.Context, expected error) { + t := func(name string, ctx context.Context, expected error) { test.Run(name, func(test *testing.T) { - var err = common.Sleep(ctx, dt) + err := common.Sleep(ctx, dt) if !errors.Is(err, expected) { test.Errorf("expected %v, got %v", expected, err) } }) } - var ctx = context.Background() - var canceled, cancel = context.WithCancel(ctx) + ctx := context.Background() + canceled, cancel := context.WithCancel(ctx) cancel() t("background context", ctx, nil) diff --git a/load/load_aix.go b/load/load_aix.go index b3cc8f0..e7f9f94 100644 --- a/load/load_aix.go +++ b/load/load_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package load diff --git a/load/load_darwin.go b/load/load_darwin.go index a205f2f..73e62ca 100644 --- a/load/load_darwin.go +++ b/load/load_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package load diff --git a/load/load_fallback.go b/load/load_fallback.go index 17126ac..3e41fd1 100644 --- a/load/load_fallback.go +++ b/load/load_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix // +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix package load diff --git a/load/load_freebsd.go b/load/load_freebsd.go index bee8f55..4069805 100644 --- a/load/load_freebsd.go +++ b/load/load_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package load diff --git a/load/load_linux.go b/load/load_linux.go index cfe68d9..30bba35 100644 --- a/load/load_linux.go +++ b/load/load_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package load diff --git a/load/load_openbsd.go b/load/load_openbsd.go index b299f58..1d5d611 100644 --- a/load/load_openbsd.go +++ b/load/load_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package load diff --git a/load/load_solaris.go b/load/load_solaris.go index ae47dff..b9dd273 100644 --- a/load/load_solaris.go +++ b/load/load_solaris.go @@ -1,3 +1,4 @@ +//go:build solaris // +build solaris package load diff --git a/load/load_test.go b/load/load_test.go index a9db11b..1790fa5 100644 --- a/load/load_test.go +++ b/load/load_test.go @@ -71,7 +71,6 @@ func TestMiscStatString(t *testing.T) { } func BenchmarkLoad(b *testing.B) { - loadAvg := func(t testing.TB) { v, err := Avg() skipIfNotImplementedErr(t, err) diff --git a/load/load_windows.go b/load/load_windows.go index 54688f7..3ff0c0a 100644 --- a/load/load_windows.go +++ b/load/load_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package load diff --git a/mem/mem_aix.go b/mem/mem_aix.go index 312a569..9b2196d 100644 --- a/mem/mem_aix.go +++ b/mem/mem_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package mem diff --git a/mem/mem_bsd.go b/mem/mem_bsd.go index 88db762..a0b8be0 100644 --- a/mem/mem_bsd.go +++ b/mem/mem_bsd.go @@ -1,3 +1,4 @@ +//go:build freebsd || openbsd // +build freebsd openbsd package mem diff --git a/mem/mem_bsd_test.go b/mem/mem_bsd_test.go index ad3838e..9839a04 100644 --- a/mem/mem_bsd_test.go +++ b/mem/mem_bsd_test.go @@ -1,3 +1,4 @@ +//go:build freebsd || openbsd // +build freebsd openbsd package mem diff --git a/mem/mem_darwin.go b/mem/mem_darwin.go index 187c52c..0527dd9 100644 --- a/mem/mem_darwin.go +++ b/mem/mem_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package mem diff --git a/mem/mem_darwin_cgo.go b/mem/mem_darwin_cgo.go index ade3cec..82c3824 100644 --- a/mem/mem_darwin_cgo.go +++ b/mem/mem_darwin_cgo.go @@ -1,3 +1,4 @@ +//go:build darwin && cgo // +build darwin,cgo package mem diff --git a/mem/mem_darwin_nocgo.go b/mem/mem_darwin_nocgo.go index 2e847cb..be926f2 100644 --- a/mem/mem_darwin_nocgo.go +++ b/mem/mem_darwin_nocgo.go @@ -1,3 +1,4 @@ +//go:build darwin && !cgo // +build darwin,!cgo package mem diff --git a/mem/mem_darwin_test.go b/mem/mem_darwin_test.go index dba421f..4e0d9a0 100644 --- a/mem/mem_darwin_test.go +++ b/mem/mem_darwin_test.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package mem diff --git a/mem/mem_fallback.go b/mem/mem_fallback.go index 6890f2b..0b6c528 100644 --- a/mem/mem_fallback.go +++ b/mem/mem_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !plan9 && !aix // +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!plan9,!aix package mem diff --git a/mem/mem_freebsd.go b/mem/mem_freebsd.go index ad59213..44543ef 100644 --- a/mem/mem_freebsd.go +++ b/mem/mem_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package mem diff --git a/mem/mem_linux.go b/mem/mem_linux.go index 08c087b..cea5400 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package mem @@ -331,7 +332,7 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { Free: uint64(sysinfo.Freeswap) * uint64(sysinfo.Unit), } ret.Used = ret.Total - ret.Free - //check Infinity + // check Infinity if ret.Total != 0 { ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0 } else { @@ -394,7 +395,6 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6 fn := common.HostProc("zoneinfo") lines, err := common.ReadLines(fn) - if err != nil { return ret.Free + ret.Cached // fallback under kernel 2.6.13 } @@ -407,7 +407,6 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6 if strings.HasPrefix(fields[0], "low") { lowValue, err := strconv.ParseUint(fields[1], 10, 64) - if err != nil { lowValue = 0 } diff --git a/mem/mem_linux_test.go b/mem/mem_linux_test.go index 3448729..42e7ff5 100644 --- a/mem/mem_linux_test.go +++ b/mem/mem_linux_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package mem @@ -25,79 +26,83 @@ var virtualMemoryTests = []struct { mockedRootFS string stat *VirtualMemoryStat }{ - {"intelcorei5", &VirtualMemoryStat{ - Total: 16502300672, - Available: 11495358464, - Used: 3437277184, - UsedPercent: 20.82907863769651, - Free: 8783491072, - Active: 4347392000, - Inactive: 2938834944, - Wired: 0, - Laundry: 0, - Buffers: 212496384, - Cached: 4069036032, - WriteBack: 0, - Dirty: 176128, - WriteBackTmp: 0, - Shared: 1222402048, - Slab: 253771776, - Sreclaimable: 186470400, - Sunreclaim: 67301376, - PageTables: 65241088, - SwapCached: 0, - CommitLimit: 16509730816, - CommittedAS: 12360818688, - HighTotal: 0, - HighFree: 0, - LowTotal: 0, - LowFree: 0, - SwapTotal: 8258580480, - SwapFree: 8258580480, - Mapped: 1172627456, - VmallocTotal: 35184372087808, - VmallocUsed: 0, - VmallocChunk: 0, - HugePagesTotal: 0, - HugePagesFree: 0, - HugePageSize: 2097152}, + { + "intelcorei5", &VirtualMemoryStat{ + Total: 16502300672, + Available: 11495358464, + Used: 3437277184, + UsedPercent: 20.82907863769651, + Free: 8783491072, + Active: 4347392000, + Inactive: 2938834944, + Wired: 0, + Laundry: 0, + Buffers: 212496384, + Cached: 4069036032, + WriteBack: 0, + Dirty: 176128, + WriteBackTmp: 0, + Shared: 1222402048, + Slab: 253771776, + Sreclaimable: 186470400, + Sunreclaim: 67301376, + PageTables: 65241088, + SwapCached: 0, + CommitLimit: 16509730816, + CommittedAS: 12360818688, + HighTotal: 0, + HighFree: 0, + LowTotal: 0, + LowFree: 0, + SwapTotal: 8258580480, + SwapFree: 8258580480, + Mapped: 1172627456, + VmallocTotal: 35184372087808, + VmallocUsed: 0, + VmallocChunk: 0, + HugePagesTotal: 0, + HugePagesFree: 0, + HugePageSize: 2097152, + }, }, - {"issue1002", &VirtualMemoryStat{ - Total: 260579328, - Available: 215199744, - Used: 34328576, - UsedPercent: 13.173944481121694, - Free: 124506112, - Active: 108785664, - Inactive: 8581120, - Wired: 0, - Laundry: 0, - Buffers: 4915200, - Cached: 96829440, - WriteBack: 0, - Dirty: 0, - WriteBackTmp: 0, - Shared: 0, - Slab: 9293824, - Sreclaimable: 2764800, - Sunreclaim: 6529024, - PageTables: 405504, - SwapCached: 0, - CommitLimit: 130289664, - CommittedAS: 25567232, - HighTotal: 134217728, - HighFree: 67784704, - LowTotal: 126361600, - LowFree: 56721408, - SwapTotal: 0, - SwapFree: 0, - Mapped: 38793216, - VmallocTotal: 1996488704, - VmallocUsed: 0, - VmallocChunk: 0, - HugePagesTotal: 0, - HugePagesFree: 0, - HugePageSize: 0}, + { + "issue1002", &VirtualMemoryStat{ + Total: 260579328, + Available: 215199744, + Used: 34328576, + UsedPercent: 13.173944481121694, + Free: 124506112, + Active: 108785664, + Inactive: 8581120, + Wired: 0, + Laundry: 0, + Buffers: 4915200, + Cached: 96829440, + WriteBack: 0, + Dirty: 0, + WriteBackTmp: 0, + Shared: 0, + Slab: 9293824, + Sreclaimable: 2764800, + Sunreclaim: 6529024, + PageTables: 405504, + SwapCached: 0, + CommitLimit: 130289664, + CommittedAS: 25567232, + HighTotal: 134217728, + HighFree: 67784704, + LowTotal: 126361600, + LowFree: 56721408, + SwapTotal: 0, + SwapFree: 0, + Mapped: 38793216, + VmallocTotal: 1996488704, + VmallocUsed: 0, + VmallocChunk: 0, + HugePagesTotal: 0, + HugePagesFree: 0, + HugePageSize: 0, + }, }, } diff --git a/mem/mem_openbsd.go b/mem/mem_openbsd.go index 9dc3af1..4d9b6cc 100644 --- a/mem/mem_openbsd.go +++ b/mem/mem_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package mem diff --git a/mem/mem_openbsd_386.go b/mem/mem_openbsd_386.go index 0fa65d9..de2b26c 100644 --- a/mem/mem_openbsd_386.go +++ b/mem/mem_openbsd_386.go @@ -1,3 +1,4 @@ +//go:build openbsd && 386 // +build openbsd,386 // Code generated by cmd/cgo -godefs; DO NOT EDIT. diff --git a/mem/mem_openbsd_arm64.go b/mem/mem_openbsd_arm64.go index 35f8517..3661b16 100644 --- a/mem/mem_openbsd_arm64.go +++ b/mem/mem_openbsd_arm64.go @@ -1,3 +1,4 @@ +//go:build openbsd && arm64 // +build openbsd,arm64 // Code generated by cmd/cgo -godefs; DO NOT EDIT. diff --git a/mem/mem_plan9.go b/mem/mem_plan9.go index 8e7c433..b5259f8 100644 --- a/mem/mem_plan9.go +++ b/mem/mem_plan9.go @@ -1,3 +1,4 @@ +//go:build plan9 // +build plan9 package mem diff --git a/mem/mem_plan9_test.go b/mem/mem_plan9_test.go index 94097bd..b3480ca 100644 --- a/mem/mem_plan9_test.go +++ b/mem/mem_plan9_test.go @@ -1,3 +1,4 @@ +//go:build plan9 // +build plan9 package mem @@ -12,14 +13,16 @@ var virtualMemoryTests = []struct { mockedRootFS string stat *VirtualMemoryStat }{ - {"swap", &VirtualMemoryStat{ - Total: 1071185920, - Available: 808370176, - Used: 11436032, - UsedPercent: 1.3949677238843257, - Free: 808370176, - SwapTotal: 655360000, - SwapFree: 655360000}, + { + "swap", &VirtualMemoryStat{ + Total: 1071185920, + Available: 808370176, + Used: 11436032, + UsedPercent: 1.3949677238843257, + Free: 808370176, + SwapTotal: 655360000, + SwapFree: 655360000, + }, }, } @@ -49,10 +52,12 @@ var swapMemoryTests = []struct { mockedRootFS string swap *SwapMemoryStat }{ - {"swap", &SwapMemoryStat{ - Total: 655360000, - Used: 0, - Free: 655360000}, + { + "swap", &SwapMemoryStat{ + Total: 655360000, + Used: 0, + Free: 655360000, + }, }, } diff --git a/mem/mem_solaris.go b/mem/mem_solaris.go index 9f09f82..7f6a6fd 100644 --- a/mem/mem_solaris.go +++ b/mem/mem_solaris.go @@ -1,3 +1,4 @@ +//go:build solaris // +build solaris package mem diff --git a/mem/mem_solaris_test.go b/mem/mem_solaris_test.go index 907e49d..0536020 100644 --- a/mem/mem_solaris_test.go +++ b/mem/mem_solaris_test.go @@ -1,3 +1,4 @@ +//go:build solaris // +build solaris package mem diff --git a/mem/mem_windows.go b/mem/mem_windows.go index 4d33713..8c7fb1a 100644 --- a/mem/mem_windows.go +++ b/mem/mem_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package mem diff --git a/mem/types_openbsd.go b/mem/types_openbsd.go index bb841a4..8e0e412 100644 --- a/mem/types_openbsd.go +++ b/mem/types_openbsd.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore /* diff --git a/net/net_aix.go b/net/net_aix.go index e954d56..d89db7c 100644 --- a/net/net_aix.go +++ b/net/net_aix.go @@ -1,3 +1,4 @@ +//go:build aix // +build aix package net @@ -102,7 +103,6 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat, return getIOCountersAll(iocounters) } return iocounters, nil - } // NetIOCountersByFile is an method which is added just a compatibility for linux. @@ -335,7 +335,6 @@ func parseNetstatA(output string, kind string) ([]ConnectionStat, error) { } return ret, nil - } func Connections(kind string) ([]ConnectionStat, error) { @@ -343,7 +342,6 @@ func Connections(kind string) ([]ConnectionStat, error) { } func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, error) { - args := []string{"-na"} switch strings.ToLower(kind) { default: @@ -367,7 +365,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, return nil, err } out, err := invoke.CommandWithContext(ctx, netstat, args...) - if err != nil { return nil, err } @@ -378,7 +375,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, } return ret, nil - } func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { diff --git a/net/net_darwin.go b/net/net_darwin.go index 2327031..9badcf6 100644 --- a/net/net_darwin.go +++ b/net/net_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package net @@ -6,11 +7,12 @@ import ( "context" "errors" "fmt" - "github.com/shirou/gopsutil/v3/internal/common" "os/exec" "regexp" "strconv" "strings" + + "github.com/shirou/gopsutil/v3/internal/common" ) var ( diff --git a/net/net_fallback.go b/net/net_fallback.go index 6220e83..58325f6 100644 --- a/net/net_fallback.go +++ b/net/net_fallback.go @@ -1,3 +1,4 @@ +//go:build !aix && !darwin && !linux && !freebsd && !openbsd && !windows // +build !aix,!darwin,!linux,!freebsd,!openbsd,!windows package net diff --git a/net/net_freebsd.go b/net/net_freebsd.go index 739f8cc..0a30423 100644 --- a/net/net_freebsd.go +++ b/net/net_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package net diff --git a/net/net_linux.go b/net/net_linux.go index b1d1626..d856b9e 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package net @@ -233,7 +234,6 @@ func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) { maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max") count, err := common.ReadInts(countfile) - if err != nil { return nil, err } @@ -331,21 +331,25 @@ var kindTCP4 = netConnectionKindType{ sockType: syscall.SOCK_STREAM, filename: "tcp", } + var kindTCP6 = netConnectionKindType{ family: syscall.AF_INET6, sockType: syscall.SOCK_STREAM, filename: "tcp6", } + var kindUDP4 = netConnectionKindType{ family: syscall.AF_INET, sockType: syscall.SOCK_DGRAM, filename: "udp", } + var kindUDP6 = netConnectionKindType{ family: syscall.AF_INET6, sockType: syscall.SOCK_DGRAM, filename: "udp6", } + var kindUNIX = netConnectionKindType{ family: syscall.AF_UNIX, filename: "unix", @@ -747,7 +751,6 @@ func parseIPv6HexString(src []byte) (net.IP, error) { } func processInet(file string, kind netConnectionKindType, inodes map[string][]inodeMap, filterPid int32) ([]connTmp, error) { - if strings.HasSuffix(file, "6") && !common.PathExists(file) { // IPv6 not supported, return empty. return []connTmp{}, nil diff --git a/net/net_linux_netlink_test.go b/net/net_linux_netlink_test.go index 67007de..8897196 100644 --- a/net/net_linux_netlink_test.go +++ b/net/net_linux_netlink_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package net @@ -10,6 +11,7 @@ func BenchmarkGetConnectionsInet(b *testing.B) { Connections("inet") } } + func BenchmarkGetConnectionsAll(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { diff --git a/net/net_openbsd.go b/net/net_openbsd.go index 4e09a66..04b9b1d 100644 --- a/net/net_openbsd.go +++ b/net/net_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package net @@ -298,7 +299,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, return nil, err } out, err := invoke.CommandWithContext(ctx, netstat, args...) - if err != nil { return nil, err } diff --git a/net/net_test.go b/net/net_test.go index ed633cf..bacca04 100644 --- a/net/net_test.go +++ b/net/net_test.go @@ -50,7 +50,6 @@ func TestNetProtoCountersStatString(t *testing.T) { if e != fmt.Sprintf("%v", v) { t.Errorf("NetProtoCountersStat string is invalid: %v", v) } - } func TestNetConnectionStatString(t *testing.T) { @@ -64,7 +63,6 @@ func TestNetConnectionStatString(t *testing.T) { if e != fmt.Sprintf("%v", v) { t.Errorf("NetConnectionStat string is invalid: %v", v) } - } func TestNetIOCountersAll(t *testing.T) { @@ -223,7 +221,6 @@ func TestNetConnections(t *testing.T) { t.Errorf("invalid NetConnections: %v", vv) } } - } func TestNetFilterCounters(t *testing.T) { @@ -251,7 +248,6 @@ func TestNetFilterCounters(t *testing.T) { t.Errorf("nf_connTrackMax needs to be greater than zero: %v", vv) } } - } func TestInterfaceStatString(t *testing.T) { diff --git a/net/net_unix.go b/net/net_unix.go index 924cfd1..2fd2224 100644 --- a/net/net_unix.go +++ b/net/net_unix.go @@ -1,3 +1,4 @@ +//go:build freebsd || darwin // +build freebsd darwin package net @@ -80,7 +81,6 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C } n, err := parseNetLine(rr) if err != nil { - continue } diff --git a/net/net_windows.go b/net/net_windows.go index d450e27..f742d82 100644 --- a/net/net_windows.go +++ b/net/net_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package net @@ -44,16 +45,19 @@ var kindTCP4 = netConnectionKindType{ sockType: syscall.SOCK_STREAM, filename: "tcp", } + var kindTCP6 = netConnectionKindType{ family: syscall.AF_INET6, sockType: syscall.SOCK_STREAM, filename: "tcp6", } + var kindUDP4 = netConnectionKindType{ family: syscall.AF_INET, sockType: syscall.SOCK_DGRAM, filename: "udp", } + var kindUDP6 = netConnectionKindType{ family: syscall.AF_INET6, sockType: syscall.SOCK_DGRAM, @@ -524,9 +528,7 @@ func getUDPConnections(family uint32) ([]ConnectionStat, error) { buf = make([]byte, size) } - var ( - index, step, length int - ) + var index, step, length int stats := make([]ConnectionStat, 0) switch family { @@ -693,8 +695,10 @@ type mibTCP6TableOwnerPid struct { Table [anySize]mibTCP6RowOwnerPid } -type pmibTCPTableOwnerPidAll *mibTCPTableOwnerPid -type pmibTCP6TableOwnerPidAll *mibTCP6TableOwnerPid +type ( + pmibTCPTableOwnerPidAll *mibTCPTableOwnerPid + pmibTCP6TableOwnerPidAll *mibTCP6TableOwnerPid +) // UDP @@ -749,8 +753,10 @@ type mibUDP6TableOwnerPid struct { Table [anySize]mibUDP6RowOwnerPid } -type pmibUDPTableOwnerPid *mibUDPTableOwnerPid -type pmibUDP6TableOwnerPid *mibUDP6TableOwnerPid +type ( + pmibUDPTableOwnerPid *mibUDPTableOwnerPid + pmibUDP6TableOwnerPid *mibUDP6TableOwnerPid +) func decodePort(port uint32) uint16 { return syscall.Ntohs(uint16(port)) diff --git a/net/types_darwin.go b/net/types_darwin.go index 1494b2d..81aca01 100644 --- a/net/types_darwin.go +++ b/net/types_darwin.go @@ -1,4 +1,6 @@ +//go:build ignore // +build ignore + // Hand writing: _Ctype_struct___3, 4 /* @@ -42,12 +44,14 @@ type ( _C_long_double C.longlong ) -type Xinpgen C.struct_xinpgen -type Inpcb C.struct_inpcb -type in_addr C.struct_in_addr -type Inpcb_list_entry C.struct__inpcb_list_entry -type Xsocket C.struct_xsocket -type Xsockbuf C.struct_xsockbuf -type Xinpcb C.struct_xinpcb +type ( + Xinpgen C.struct_xinpgen + Inpcb C.struct_inpcb + in_addr C.struct_in_addr + Inpcb_list_entry C.struct__inpcb_list_entry + Xsocket C.struct_xsocket + Xsockbuf C.struct_xsockbuf + Xinpcb C.struct_xinpcb +) -//type u_quad_t C.struct_u_quad_t +// type u_quad_t C.struct_u_quad_t diff --git a/process/process_bsd.go b/process/process_bsd.go index 26b17e9..263829f 100644 --- a/process/process_bsd.go +++ b/process/process_bsd.go @@ -1,3 +1,4 @@ +//go:build darwin || freebsd || openbsd // +build darwin freebsd openbsd package process diff --git a/process/process_darwin.go b/process/process_darwin.go index e43dbd8..c1dc918 100644 --- a/process/process_darwin.go +++ b/process/process_darwin.go @@ -1,3 +1,4 @@ +//go:build darwin // +build darwin package process @@ -125,7 +126,7 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) { elapsedDurations = append(elapsedDurations, time.Duration(p)) } - var elapsed = time.Duration(elapsedDurations[0]) * time.Second + elapsed := time.Duration(elapsedDurations[0]) * time.Second if len(elapsedDurations) > 1 { elapsed += time.Duration(elapsedDurations[1]) * time.Minute } @@ -305,7 +306,6 @@ func convertCPUTimes(s string) (ret float64, err error) { func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) { r, err := callPsWithContext(ctx, "utime,stime", p.Pid, false, false) - if err != nil { return nil, err } diff --git a/process/process_darwin_386.go b/process/process_darwin_386.go index f8e9223..b353e5e 100644 --- a/process/process_darwin_386.go +++ b/process/process_darwin_386.go @@ -218,10 +218,12 @@ type AuditinfoAddr struct { Asid int32 Flags uint64 } + type AuMask struct { Success uint32 Failure uint32 } + type AuTidAddr struct { Port int32 Type uint32 diff --git a/process/process_darwin_amd64.go b/process/process_darwin_amd64.go index f8e9223..b353e5e 100644 --- a/process/process_darwin_amd64.go +++ b/process/process_darwin_amd64.go @@ -218,10 +218,12 @@ type AuditinfoAddr struct { Asid int32 Flags uint64 } + type AuMask struct { Success uint32 Failure uint32 } + type AuTidAddr struct { Port int32 Type uint32 diff --git a/process/process_darwin_arm64.go b/process/process_darwin_arm64.go index 92bd425..cbd6bdc 100644 --- a/process/process_darwin_arm64.go +++ b/process/process_darwin_arm64.go @@ -1,5 +1,6 @@ -// +build darwin -// +build arm64 +//go:build darwin && arm64 +// +build darwin,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs process/types_darwin.go diff --git a/process/process_darwin_cgo.go b/process/process_darwin_cgo.go index 9b9d393..972b74b 100644 --- a/process/process_darwin_cgo.go +++ b/process/process_darwin_cgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build cgo +//go:build darwin && cgo +// +build darwin,cgo package process @@ -10,6 +10,7 @@ package process // #include // #include import "C" + import ( "bytes" "context" diff --git a/process/process_darwin_nocgo.go b/process/process_darwin_nocgo.go index 91f2fc6..1426c97 100644 --- a/process/process_darwin_nocgo.go +++ b/process/process_darwin_nocgo.go @@ -1,5 +1,5 @@ -// +build darwin -// +build !cgo +//go:build darwin && !cgo +// +build darwin,!cgo package process diff --git a/process/process_fallback.go b/process/process_fallback.go index 2638d8c..e1c4809 100644 --- a/process/process_fallback.go +++ b/process/process_fallback.go @@ -1,3 +1,4 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !plan9 // +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!plan9 package process @@ -27,8 +28,7 @@ type MemoryMapsStat struct { Swap uint64 `json:"swap"` } -type MemoryInfoExStat struct { -} +type MemoryInfoExStat struct{} func pidsWithContext(ctx context.Context) ([]int32, error) { return nil, common.ErrNotImplementedError diff --git a/process/process_freebsd.go b/process/process_freebsd.go index 63f0136..a010383 100644 --- a/process/process_freebsd.go +++ b/process/process_freebsd.go @@ -1,3 +1,4 @@ +//go:build freebsd // +build freebsd package process diff --git a/process/process_freebsd_arm64.go b/process/process_freebsd_arm64.go index 22679fd..effd470 100644 --- a/process/process_freebsd_arm64.go +++ b/process/process_freebsd_arm64.go @@ -1,5 +1,6 @@ -// +build freebsd -// +build arm64 +//go:build freebsd && arm64 +// +build freebsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs process/types_freebsd.go diff --git a/process/process_linux.go b/process/process_linux.go index 670dffe..442b40a 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package process @@ -251,7 +252,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ( case RLIMIT_AS: rs.Used = uint64(p.memInfo.VMS) case RLIMIT_LOCKS: - //TODO we can get the used value from /proc/$pid/locks. But linux doesn't enforce it, so not a high priority. + // TODO we can get the used value from /proc/$pid/locks. But linux doesn't enforce it, so not a high priority. case RLIMIT_SIGPENDING: rs.Used = p.sigInfo.PendingProcess case RLIMIT_NICE: @@ -345,7 +346,6 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e return nil, err } return pageFaults, nil - } func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) { @@ -548,7 +548,7 @@ func (p *Process) fillFromLimitsWithContext() ([]RlimitStat, error) { // Remove last item from string str = str[:len(str)-1] - //Now last item is a Soft limit + // Now last item is a Soft limit statItem.Soft, err = limitToUint(str[len(str)-1]) if err != nil { return nil, err @@ -556,7 +556,7 @@ func (p *Process) fillFromLimitsWithContext() ([]RlimitStat, error) { // Remove last item from string str = str[:len(str)-1] - //The rest is a stats name + // The rest is a stats name resourceName := strings.Join(str, " ") switch resourceName { case "Max cpu time": diff --git a/process/process_linux_test.go b/process/process_linux_test.go index a374b4c..b98707f 100644 --- a/process/process_linux_test.go +++ b/process/process_linux_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux package process diff --git a/process/process_openbsd.go b/process/process_openbsd.go index 9878fd7..cdbdaed 100644 --- a/process/process_openbsd.go +++ b/process/process_openbsd.go @@ -1,3 +1,4 @@ +//go:build openbsd // +build openbsd package process @@ -80,7 +81,6 @@ func (p *Process) ExeWithContext(ctx context.Context) (string, error) { func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) { mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv} buf, _, err := common.CallSyscall(mib) - if err != nil { return nil, err } @@ -318,7 +318,6 @@ func ProcessesWithContext(ctx context.Context) ([]*Process, error) { results := []*Process{} buf, length, err := callKernProcSyscall(KernProcAll, 0) - if err != nil { return results, err } diff --git a/process/process_openbsd_386.go b/process/process_openbsd_386.go index b89fb8d..f4ed024 100644 --- a/process/process_openbsd_386.go +++ b/process/process_openbsd_386.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build 386 +//go:build openbsd && 386 +// +build openbsd,386 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs process/types_openbsd.go diff --git a/process/process_openbsd_arm64.go b/process/process_openbsd_arm64.go index 2d97fbc..a3291b8 100644 --- a/process/process_openbsd_arm64.go +++ b/process/process_openbsd_arm64.go @@ -1,5 +1,6 @@ -// +build openbsd -// +build arm64 +//go:build openbsd && arm64 +// +build openbsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs process/types_openbsd.go diff --git a/process/process_plan9.go b/process/process_plan9.go index ff4a5cf..70e11e3 100644 --- a/process/process_plan9.go +++ b/process/process_plan9.go @@ -1,3 +1,4 @@ +//go:build plan9 // +build plan9 package process @@ -27,8 +28,7 @@ type MemoryMapsStat struct { Swap uint64 `json:"swap"` } -type MemoryInfoExStat struct { -} +type MemoryInfoExStat struct{} func pidsWithContext(ctx context.Context) ([]int32, error) { return nil, common.ErrNotImplementedError diff --git a/process/process_posix.go b/process/process_posix.go index 11cf9f7..88e2bff 100644 --- a/process/process_posix.go +++ b/process/process_posix.go @@ -1,3 +1,4 @@ +//go:build linux || freebsd || openbsd || darwin || solaris // +build linux freebsd openbsd darwin solaris package process diff --git a/process/process_posix_test.go b/process/process_posix_test.go index a5cacb3..201a58c 100644 --- a/process/process_posix_test.go +++ b/process/process_posix_test.go @@ -1,3 +1,4 @@ +//go:build linux || freebsd // +build linux freebsd package process diff --git a/process/process_race_test.go b/process/process_race_test.go index fd444a8..93c078d 100644 --- a/process/process_race_test.go +++ b/process/process_race_test.go @@ -1,3 +1,4 @@ +//go:build race // +build race package process diff --git a/process/process_solaris.go b/process/process_solaris.go index 2b695af..93a6e01 100644 --- a/process/process_solaris.go +++ b/process/process_solaris.go @@ -27,8 +27,7 @@ type MemoryMapsStat struct { Swap uint64 `json:"swap"` } -type MemoryInfoExStat struct { -} +type MemoryInfoExStat struct{} func pidsWithContext(ctx context.Context) ([]int32, error) { return readPidsFromDir(common.HostProc()) diff --git a/process/process_test.go b/process/process_test.go index 07b8fc5..2bb72b8 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -65,6 +65,7 @@ func Test_Pids_Fail(t *testing.T) { t.Errorf("wrong getted pid nums: %v/%d", ret, len(ret)) } } + func Test_Pid_exists(t *testing.T) { checkPid := os.Getpid() @@ -93,7 +94,6 @@ func Test_NewProcess(t *testing.T) { t.Errorf("error %v", ret) } } - } func Test_Process_memory_maps(t *testing.T) { @@ -131,6 +131,7 @@ func Test_Process_memory_maps(t *testing.T) { t.Errorf("memory map is empty") } } + func Test_Process_MemoryInfo(t *testing.T) { p := testGetProcess() @@ -316,6 +317,7 @@ func Test_Process_Name(t *testing.T) { t.Errorf("invalid Exe %s", n) } } + func Test_Process_Long_Name_With_Spaces(t *testing.T) { tmpdir, err := ioutil.TempDir("", "") if err != nil { @@ -361,6 +363,7 @@ func Test_Process_Long_Name_With_Spaces(t *testing.T) { } cmd.Process.Kill() } + func Test_Process_Long_Name(t *testing.T) { tmpdir, err := ioutil.TempDir("", "") if err != nil { @@ -406,6 +409,7 @@ func Test_Process_Long_Name(t *testing.T) { } cmd.Process.Kill() } + func Test_Process_Exe(t *testing.T) { p := testGetProcess() diff --git a/process/process_windows.go b/process/process_windows.go index f502720..282b0d9 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package process @@ -70,11 +71,9 @@ type systemInfo struct { } // Memory_info_ex is different between OSes -type MemoryInfoExStat struct { -} +type MemoryInfoExStat struct{} -type MemoryMapsStat struct { -} +type MemoryMapsStat struct{} // ioCounters is an equivalent representation of IO_COUNTERS in the Windows API. // https://docs.microsoft.com/windows/win32/api/winnt/ns-winnt-io_counters @@ -195,8 +194,10 @@ type winTokenPriviledges struct { Privileges [1]winLUIDAndAttributes } -type winLong int32 -type winDWord uint32 +type ( + winLong int32 + winDWord uint32 +) func init() { var systemInfo systemInfo @@ -261,7 +262,6 @@ func pidsWithContext(ctx context.Context) ([]int32, error) { return ret, nil } - } func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) { @@ -431,7 +431,7 @@ func (p *Process) CwdWithContext(_ context.Context) (string, error) { } } - //if we reach here, we have no cwd + // if we reach here, we have no cwd return "", nil } @@ -1018,14 +1018,14 @@ func is32BitProcess(h windows.Handle) bool { procIs32Bits = true } } else { - //if the OS does not support the call, we fallback into the bitness of the app + // if the OS does not support the call, we fallback into the bitness of the app if unsafe.Sizeof(wow64) == 4 { procIs32Bits = true } } default: - //for other unknown platforms, we rely on process platform + // for other unknown platforms, we rely on process platform if unsafe.Sizeof(processorArchitecture) == 8 { procIs32Bits = false } else { @@ -1159,7 +1159,7 @@ func getProcessCommandLine(pid int32) (string, error) { } } - //if we reach here, we have no command line + // if we reach here, we have no command line return "", nil } diff --git a/process/process_windows_386.go b/process/process_windows_386.go index 1223be6..982287d 100644 --- a/process/process_windows_386.go +++ b/process/process_windows_386.go @@ -28,7 +28,7 @@ type PROCESS_MEMORY_COUNTERS struct { func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, error) { if is32BitProcess { - //we are on a 32-bit process reading an external 32-bit process + // we are on a 32-bit process reading an external 32-bit process var info processBasicInformation32 ret, _, _ := common.ProcNtQueryInformationProcess.Call( @@ -44,8 +44,8 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, er return 0, windows.NTStatus(ret) } } else { - //we are on a 32-bit process reading an external 64-bit process - if common.ProcNtWow64QueryInformationProcess64.Find() == nil { //avoid panic + // we are on a 32-bit process reading an external 64-bit process + if common.ProcNtWow64QueryInformationProcess64.Find() == nil { // avoid panic var info processBasicInformation64 ret, _, _ := common.ProcNtWow64QueryInformationProcess64.Call( @@ -83,19 +83,19 @@ func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, si return buffer[:read] } } else { - //reading a 64-bit process from a 32-bit one - if common.ProcNtWow64ReadVirtualMemory64.Find() == nil { //avoid panic + // reading a 64-bit process from a 32-bit one + if common.ProcNtWow64ReadVirtualMemory64.Find() == nil { // avoid panic var read uint64 buffer := make([]byte, size) ret, _, _ := common.ProcNtWow64ReadVirtualMemory64.Call( uintptr(h), - uintptr(address&0xFFFFFFFF), //the call expects a 64-bit value + uintptr(address&0xFFFFFFFF), // the call expects a 64-bit value uintptr(address>>32), uintptr(unsafe.Pointer(&buffer[0])), - uintptr(size), //the call expects a 64-bit value - uintptr(0), //but size is 32-bit so pass zero as the high dword + uintptr(size), // the call expects a 64-bit value + uintptr(0), // but size is 32-bit so pass zero as the high dword uintptr(unsafe.Pointer(&read)), ) if int(ret) >= 0 && read > 0 { @@ -104,6 +104,6 @@ func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, si } } - //if we reach here, an error happened + // if we reach here, an error happened return nil } diff --git a/process/process_windows_amd64.go b/process/process_windows_amd64.go index 79844b5..74c6212 100644 --- a/process/process_windows_amd64.go +++ b/process/process_windows_amd64.go @@ -26,7 +26,7 @@ type PROCESS_MEMORY_COUNTERS struct { func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, error) { if is32BitProcess { - //we are on a 64-bit process reading an external 32-bit process + // we are on a 64-bit process reading an external 32-bit process var wow64 uint ret, _, _ := common.ProcNtQueryInformationProcess.Call( @@ -42,7 +42,7 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, er return 0, windows.NTStatus(ret) } } else { - //we are on a 64-bit process reading an external 64-bit process + // we are on a 64-bit process reading an external 64-bit process var info processBasicInformation64 ret, _, _ := common.ProcNtQueryInformationProcess.Call( diff --git a/process/types_darwin.go b/process/types_darwin.go index 8be5f58..3cde887 100644 --- a/process/types_darwin.go +++ b/process/types_darwin.go @@ -5,6 +5,7 @@ // Hand Writing // - all pointer in ExternProc to uint64 +//go:build ignore // +build ignore /* @@ -153,9 +154,11 @@ type Posix_cred C.struct_posix_cred type Label C.struct_label -type AuditinfoAddr C.struct_auditinfo_addr -type AuMask C.struct_au_mask -type AuTidAddr C.struct_au_tid_addr +type ( + AuditinfoAddr C.struct_auditinfo_addr + AuMask C.struct_au_mask + AuTidAddr C.struct_au_tid_addr +) // TAILQ(ucred) type UcredQueue C.struct_ucred_queue diff --git a/process/types_freebsd.go b/process/types_freebsd.go index aa7b346..658d461 100644 --- a/process/types_freebsd.go +++ b/process/types_freebsd.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore // We still need editing by hands. diff --git a/process/types_openbsd.go b/process/types_openbsd.go index 09ac590..75f2344 100644 --- a/process/types_openbsd.go +++ b/process/types_openbsd.go @@ -1,3 +1,4 @@ +//go:build ignore // +build ignore // We still need editing by hands. diff --git a/winservices/manager.go b/winservices/manager.go index 1f1f937..c9957f7 100644 --- a/winservices/manager.go +++ b/winservices/manager.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package winservices diff --git a/winservices/winservices.go b/winservices/winservices.go index 4112b2c..93ec0e1 100644 --- a/winservices/winservices.go +++ b/winservices/winservices.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package winservices