Move to typical go project layout, fix golangci-lint warnings, update deps

This commit is contained in:
eleksir
2024-10-06 22:10:19 +03:00
parent 0b573aa169
commit 83970650b5
115 changed files with 9402 additions and 4920 deletions

View File

@@ -1,6 +1,6 @@
env:
CIRRUS_CLONE_DEPTH: 1
GO_VERSION: go1.21.3
GO_VERSION: go1.20
freebsd_12_task:
freebsd_instance:

View File

@@ -6,6 +6,7 @@ package sysconf
import (
"bufio"
"io/ioutil"
"os"
"runtime"
"strconv"
@@ -25,7 +26,7 @@ const (
)
func readProcFsInt64(path string, fallback int64) int64 {
data, err := os.ReadFile(path)
data, err := ioutil.ReadFile(path)
if err != nil {
return fallback
}
@@ -85,16 +86,10 @@ func getNprocsProcStat() (int64, error) {
s := bufio.NewScanner(f)
for s.Scan() {
if line := strings.TrimSpace(s.Text()); strings.HasPrefix(line, "cpu") {
cpu, _, found := strings.Cut(line, " ")
if found {
// skip first line with accumulated values
if cpu == "cpu" {
continue
}
_, err := strconv.ParseInt(cpu[len("cpu"):], 10, 64)
if err == nil {
count++
}
l := strings.SplitN(line, " ", 2)
_, err := strconv.ParseInt(l[0][3:], 10, 64)
if err == nil {
count++
}
} else {
// The current format of /proc/stat has all the
@@ -103,9 +98,6 @@ func getNprocsProcStat() (int64, error) {
break
}
}
if err := s.Err(); err != nil {
return -1, err
}
return count, nil
}

View File

@@ -25,10 +25,10 @@ const (
_POSIX2_UPE = -1
)
var clktck struct {
sync.Once
v int64
}
var (
clktck int64
clktckOnce sync.Once
)
func sysconfPOSIX(name int) (int64, error) {
// NetBSD does not define all _POSIX_* values used in sysconf_posix.go
@@ -42,6 +42,7 @@ func sysconf(name int) (int64, error) {
// Duplicate the relevant values here.
switch name {
// 1003.1
case SC_ARG_MAX:
return sysctl32("kern.argmax"), nil
@@ -54,14 +55,13 @@ func sysconf(name int) (int64, error) {
}
return -1, nil
case SC_CLK_TCK:
// TODO: use sync.OnceValue once Go 1.21 is the minimal supported version
clktck.Do(func() {
clktck.v = -1
clktckOnce.Do(func() {
clktck = -1
if ci, err := unix.SysctlClockinfo("kern.clockrate"); err == nil {
clktck.v = int64(ci.Hz)
clktck = int64(ci.Hz)
}
})
return clktck.v, nil
return clktck, nil
case SC_NGROUPS_MAX:
return sysctl32("kern.ngroups"), nil
case SC_JOB_CONTROL: