1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

Merge pull request #1417 from shirou/feature/fix_lint

fix lint
This commit is contained in:
shirou 2023-02-12 18:54:26 +09:00 committed by GitHub
commit 57bee8213a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 45 additions and 41 deletions

View File

@ -6,8 +6,8 @@ package cpu
import ( import (
"context" "context"
"regexp" "regexp"
"strings"
"strconv" "strconv"
"strings"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
) )
@ -28,19 +28,19 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
} }
ret := TimesStat{CPU: "cpu-total"} ret := TimesStat{CPU: "cpu-total"}
h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers
v := whiteSpaces.Split(lines[len(lines)-2], -1) // values v := whiteSpaces.Split(lines[len(lines)-2], -1) // values
for i, header := range h { for i, header := range h {
if t, err := strconv.ParseFloat(v[i], 64); err == nil { if t, err := strconv.ParseFloat(v[i], 64); err == nil {
switch header { switch header {
case `%usr`: case `%usr`:
ret.User = t ret.User = t
case `%sys`: case `%sys`:
ret.System = t ret.System = t
case `%wio`: case `%wio`:
ret.Iowait = t ret.Iowait = t
case `%idle`: case `%idle`:
ret.Idle = t ret.Idle = t
} }
} }
} }

View File

@ -8,8 +8,8 @@ import (
"regexp" "regexp"
"strings" "strings"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
) )
var whiteSpaces = regexp.MustCompile(`\s+`) var whiteSpaces = regexp.MustCompile(`\s+`)
@ -17,11 +17,11 @@ var startBlank = regexp.MustCompile(`^\s+`)
var ignoreFSType = map[string]bool{"procfs": true} var ignoreFSType = map[string]bool{"procfs": true}
var FSType = map[int]string{ var FSType = map[int]string{
0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc", 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", 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", 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) { func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
var ret []PartitionStat var ret []PartitionStat
@ -42,7 +42,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
start := 0 start := 0
finished := false finished := false
for pos, ch := range lines[1] { for pos, ch := range lines[1] {
if ch == ' ' && ! finished { if ch == ' ' && !finished {
name := strings.TrimSpace(lines[0][start:pos]) name := strings.TrimSpace(lines[0][start:pos])
colidx[name] = idx colidx[name] = idx
finished = true finished = true

View File

@ -12,9 +12,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
) )
// PartitionsWithContext returns disk partition. // PartitionsWithContext returns disk partition.

View File

@ -21,6 +21,7 @@ package common
// high-performance serialization, especially for large data structures, // high-performance serialization, especially for large data structures,
// should look at more advanced solutions such as the encoding/gob // should look at more advanced solutions such as the encoding/gob
// package or protocol buffers. // package or protocol buffers.
import ( import (
"errors" "errors"
"io" "io"

View File

@ -6,6 +6,7 @@ package common
// - linux (amd64, arm) // - linux (amd64, arm)
// - freebsd (amd64) // - freebsd (amd64)
// - windows (amd64) // - windows (amd64)
import ( import (
"bufio" "bufio"
"bytes" "bytes"

View File

@ -218,9 +218,12 @@ func WMIQueryWithContext(ctx context.Context, query string, dst interface{}, con
} }
// Convert paths using native DOS format like: // Convert paths using native DOS format like:
// "\Device\HarddiskVolume1\Windows\systemew\file.txt" //
// "\Device\HarddiskVolume1\Windows\systemew\file.txt"
//
// into: // into:
// "C:\Windows\systemew\file.txt" //
// "C:\Windows\systemew\file.txt"
func ConvertDOSPath(p string) string { func ConvertDOSPath(p string) string {
rawDrive := strings.Join(strings.Split(p, `\`)[:3], `\`) rawDrive := strings.Join(strings.Split(p, `\`)[:3], `\`)

View File

@ -53,13 +53,13 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
for _, line := range strings.Split(string(out), "\n") { for _, line := range strings.Split(string(out), "\n") {
ret.ProcsTotal++ ret.ProcsTotal++
switch line { switch line {
case "R": case "R":
case "A": case "A":
ret.ProcsRunning++ ret.ProcsRunning++
case "T": case "T":
ret.ProcsBlocked++ ret.ProcsBlocked++
default: default:
continue continue
} }
} }
return ret, nil return ret, nil

View File

@ -71,7 +71,7 @@ func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error)
swap.Total = t * pagesize swap.Total = t * pagesize
} }
if t, err := strconv.ParseUint(p[3], 10, 64); err == nil { if t, err := strconv.ParseUint(p[3], 10, 64); err == nil {
swap.Free = swap.Total - t * pagesize swap.Free = swap.Total - t*pagesize
} }
} }
break break

View File

@ -8,9 +8,8 @@ import (
"errors" "errors"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix"
) )
func VirtualMemory() (*VirtualMemoryStat, error) { func VirtualMemory() (*VirtualMemoryStat, error) {

View File

@ -9,6 +9,7 @@ import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )

View File

@ -18,14 +18,14 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
iocounters := make([]IOCountersStat, 0, len(ifs)) iocounters := make([]IOCountersStat, 0, len(ifs))
for _, netif := range ifs { for _, netif := range ifs {
n := IOCountersStat{ n := IOCountersStat{
Name: netif.Name, Name: netif.Name,
BytesSent: uint64(netif.OBytes), BytesSent: uint64(netif.OBytes),
BytesRecv: uint64(netif.IBytes), BytesRecv: uint64(netif.IBytes),
PacketsSent: uint64(netif.OPackets), PacketsSent: uint64(netif.OPackets),
PacketsRecv: uint64(netif.IPackets), PacketsRecv: uint64(netif.IPackets),
Errin: uint64(netif.OErrors), Errin: uint64(netif.OErrors),
Errout: uint64(netif.IErrors), Errout: uint64(netif.IErrors),
Dropout: uint64(netif.XmitDrops), Dropout: uint64(netif.XmitDrops),
} }
iocounters = append(iocounters, n) iocounters = append(iocounters, n)
} }

View File

@ -211,7 +211,8 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri
// Return a list of network connections // Return a list of network connections
// Available kind: // Available kind:
// reference to netConnectionKindMap //
// reference to netConnectionKindMap
func Connections(kind string) ([]ConnectionStat, error) { func Connections(kind string) ([]ConnectionStat, error) {
return ConnectionsWithContext(context.Background(), kind) return ConnectionsWithContext(context.Background(), kind)
} }

View File

@ -8,9 +8,8 @@ import (
"syscall" "syscall"
"unsafe" "unsafe"
"golang.org/x/sys/windows"
"github.com/shirou/gopsutil/v3/internal/common" "github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
) )
type PROCESS_MEMORY_COUNTERS struct { type PROCESS_MEMORY_COUNTERS struct {