Skip to content

Commit

Permalink
Merge branch 'shirou:master' into feature/netbsd-arm64-port
Browse files Browse the repository at this point in the history
  • Loading branch information
darkgeek authored Sep 23, 2023
2 parents def3572 + 2fabf15 commit 7ffb24d
Show file tree
Hide file tree
Showing 33 changed files with 201 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- id: cache-paths
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: |
${{ steps.cache-paths.outputs.cache }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ jobs:
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: 1.17
cache: false
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Release
run: make release
4 changes: 2 additions & 2 deletions .github/workflows/sbom_generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

- uses: advanced-security/sbom-generator-action@375dee8e6144d9fd0ec1f5667b4f6fb4faacefed # v0.0.1
id: sbom
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
path: ${{steps.sbom.outputs.fileName }}
name: "SBOM"
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
- id: go-env
run: |
echo "::set-output name=cache::$(go env GOCACHE)"
echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
- name: Cache go modules
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: |
${{ steps.go-env.outputs.cache }}
Expand Down
47 changes: 27 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
issues:
max-same-issues: 0
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
exclude-rules:
- linters:
- gosec
text: "G204"
- linters:
- revive
text: "var-naming"
- linters:
- revive
text: "exported"
- linters:
- revive
text: "empty-block"
- linters:
- revive
text: "unused-parameter"
linters:
enable:
- asciicheck
Expand All @@ -26,6 +26,7 @@ linters:
- gofmt
- gofumpt
- goimports
- gomodguard
- gosec
- gosimple
- importas
Expand All @@ -46,10 +47,16 @@ linters:
- structcheck
- unused
- varcheck

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/shirou)
- standard
- default
- prefix(github.com/shirou)
gomodguard:
blocked:
modules:
- io/ioutil:
recommandations:
- io
- os
6 changes: 3 additions & 3 deletions cpu/cpu_solaris_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cpu

import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"sort"
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestParseISAInfo(t *testing.T) {
}

for _, tc := range cases {
content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
content, err := os.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
if err != nil {
t.Errorf("cannot read test case: %s", err)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestParseProcessorInfo(t *testing.T) {
}

for _, tc := range cases {
content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
content, err := os.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
if err != nil {
t.Errorf("cannot read test case: %s", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func testCPUPercent(t *testing.T, percpu bool) {
if err != nil {
t.Errorf("error %v", err)
}
// Skip CircleCI which CPU num is different
if os.Getenv("CIRCLECI") != "true" {
// Skip CI which CPU num is different
if os.Getenv("CI") != "true" {
if (percpu && len(v) != numcpu) || (!percpu && len(v) != 1) {
t.Fatalf("wrong number of entries from CPUPercent: %v", v)
}
Expand Down Expand Up @@ -172,8 +172,8 @@ func testCPUPercentLastUsed(t *testing.T, percpu bool) {
if err != nil {
t.Errorf("error %v", err)
}
// Skip CircleCI which CPU num is different
if os.Getenv("CIRCLECI") != "true" {
// Skip CI which CPU num is different
if os.Getenv("CI") != "true" {
if (percpu && len(v) != numcpu) || (!percpu && len(v) != 1) {
t.Fatalf("wrong number of entries from CPUPercent: %v", v)
}
Expand Down
9 changes: 4 additions & 5 deletions disk/disk_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -497,7 +496,7 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) {

// Try to get the serial from udev data
udevDataPath := common.HostRunWithContext(ctx, fmt.Sprintf("udev/data/b%d:%d", major, minor))
if udevdata, err := ioutil.ReadFile(udevDataPath); err == nil {
if udevdata, err := os.ReadFile(udevDataPath); err == nil {
scanner := bufio.NewScanner(bytes.NewReader(udevdata))
for scanner.Scan() {
values := strings.Split(scanner.Text(), "=")
Expand All @@ -510,8 +509,8 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
// Try to get the serial from sysfs, look at the disk device (minor 0) directly
// because if it is a partition it is not going to contain any device information
devicePath := common.HostSysWithContext(ctx, fmt.Sprintf("dev/block/%d:0/device", major))
model, _ := ioutil.ReadFile(filepath.Join(devicePath, "model"))
serial, _ := ioutil.ReadFile(filepath.Join(devicePath, "serial"))
model, _ := os.ReadFile(filepath.Join(devicePath, "model"))
serial, _ := os.ReadFile(filepath.Join(devicePath, "serial"))
if len(model) > 0 && len(serial) > 0 {
return fmt.Sprintf("%s_%s", string(model), string(serial)), nil
}
Expand All @@ -526,7 +525,7 @@ func LabelWithContext(ctx context.Context, name string) (string, error) {
return "", nil
}

dmname, err := ioutil.ReadFile(dmname_filename)
dmname, err := os.ReadFile(dmname_filename)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tklauser/go-sysconf v0.3.12
github.com/yusufpapurcu/wmi v1.2.3
golang.org/x/sys v0.11.0
golang.org/x/sys v0.12.0
)

retract v3.22.11
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQ
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 2 additions & 2 deletions host/host_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/binary"
"errors"
"io/ioutil"
"io"
"os"
"strings"
"unsafe"
Expand Down Expand Up @@ -59,7 +59,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
}
defer file.Close()

buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return ret, err
}
Expand Down
6 changes: 3 additions & 3 deletions host/host_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"encoding/binary"
"io/ioutil"
"io"
"math"
"os"
"strings"
Expand Down Expand Up @@ -54,7 +54,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
}
defer file.Close()

buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return ret, err
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) {
}
defer file.Close()

buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return ret, err
}
Expand Down
16 changes: 8 additions & 8 deletions host/host_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/binary"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -91,7 +91,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
}
defer file.Close()

buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -411,13 +411,13 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
}
for _, file := range files {
// Get the name of the temperature you are reading
name, err := ioutil.ReadFile(filepath.Join(file, "type"))
name, err := os.ReadFile(filepath.Join(file, "type"))
if err != nil {
warns.Add(err)
continue
}
// Get the temperature reading
current, err := ioutil.ReadFile(filepath.Join(file, "temp"))
current, err := os.ReadFile(filepath.Join(file, "temp"))
if err != nil {
warns.Add(err)
continue
Expand Down Expand Up @@ -461,13 +461,13 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
// Get the label of the temperature you are reading
label := ""

if raw, _ = ioutil.ReadFile(basepath + "_label"); len(raw) != 0 {
if raw, _ = os.ReadFile(basepath + "_label"); len(raw) != 0 {
// Format the label from "Core 0" to "core_0"
label = strings.Join(strings.Split(strings.TrimSpace(strings.ToLower(string(raw))), " "), "_")
}

// Get the name of the temperature you are reading
if raw, err = ioutil.ReadFile(filepath.Join(directory, "name")); err != nil {
if raw, err = os.ReadFile(filepath.Join(directory, "name")); err != nil {
warns.Add(err)
continue
}
Expand All @@ -479,7 +479,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
}

// Get the temperature reading
if raw, err = ioutil.ReadFile(file); err != nil {
if raw, err = os.ReadFile(file); err != nil {
warns.Add(err)
continue
}
Expand Down Expand Up @@ -513,7 +513,7 @@ func optionalValueReadFromFile(filename string) float64 {
return 0
}

if raw, err = ioutil.ReadFile(filename); err != nil {
if raw, err = os.ReadFile(filename); err != nil {
return 0
}

Expand Down
4 changes: 2 additions & 2 deletions host/host_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"encoding/binary"
"io/ioutil"
"io"
"os"
"strings"
"unsafe"
Expand Down Expand Up @@ -65,7 +65,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
}
defer file.Close()

buf, err := ioutil.ReadAll(file)
buf, err := io.ReadAll(file)
if err != nil {
return ret, err
}
Expand Down
Loading

0 comments on commit 7ffb24d

Please sign in to comment.