🧹 🐛 fix some warnings, go-ole on mac os (#2280)

* 🧹 fix some warnings

* 🐛 fix go-ole on mac os
pull/2282/head
Serhat Şevki Dinçer 2023-01-01 23:16:38 +11:00 committed by GitHub
parent 4d43db0c79
commit 9dfdea45c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 73 deletions

View File

@ -1,5 +1,5 @@
//go:build 386
// +build 386
//go:build 386 || arm
// +build 386 arm
package ole

View File

@ -1,5 +1,5 @@
//go:build amd64
// +build amd64
//go:build amd64 || arm64 || ppc64le || s390x
// +build amd64 arm64 ppc64le s390x
package ole

View File

@ -1,13 +0,0 @@
//go:build ppc64le
// +build ppc64le
package ole
type VARIANT struct {
VT VT // 2
wReserved1 uint16 // 4
wReserved2 uint16 // 6
wReserved3 uint16 // 8
Val int64 // 16
_ [8]byte // 24
}

View File

@ -1,13 +0,0 @@
//go:build s390x
// +build s390x
package ole
type VARIANT struct {
VT VT // 2
wReserved1 uint16 // 4
wReserved2 uint16 // 6
wReserved3 uint16 // 8
Val int64 // 16
_ [8]byte // 24
}

View File

@ -42,8 +42,7 @@ func CallLsofWithContext(ctx context.Context, invoke Invoker, pid int32, args ..
}
func CallPgrepWithContext(ctx context.Context, invoke Invoker, pid int32) ([]int32, error) {
var cmd []string
cmd = []string{"-P", strconv.Itoa(int(pid))}
cmd := []string{"-P", strconv.Itoa(int(pid))}
pgrep, err := exec.LookPath("pgrep")
if err != nil {
return []int32{}, err

View File

@ -6,7 +6,7 @@ import (
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
)
var invoke common.Invoker = common.Invoke{}
var _ common.Invoke
// Memory usage statistics. Total, Available and Used contain numbers of bytes
// for human consumption.

View File

@ -125,7 +125,7 @@ func (l *ConntrackStatList) Append(c *ConntrackStat) {
}
func (l *ConntrackStatList) Items() []ConntrackStat {
items := make([]ConntrackStat, len(l.items), len(l.items))
items := make([]ConntrackStat, len(l.items))
for i, el := range l.items {
items[i] = *el
}

View File

@ -251,7 +251,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
}
if pernic == false {
if !pernic {
return getIOCountersAll(ret)
}
return ret, nil

View File

@ -164,8 +164,8 @@ func NewProcess(pid int32) (*Process, error) {
if !exists {
return p, ErrorProcessNotRunning
}
p.CreateTime()
return p, nil
_, err = p.CreateTime()
return p, err
}
func PidExists(pid int32) (bool, error) {

View File

@ -417,9 +417,9 @@ func convertCPUTimes(s string) (ret float64, err error) {
if err != nil {
return ret, err
}
h, err := strconv.Atoi(_t[0])
h, _ := strconv.Atoi(_t[0])
t += h * ClockTicks
h, err = strconv.Atoi(_t[1])
h, _ = strconv.Atoi(_t[1])
t += h
return float64(t) / ClockTicks, nil
}
@ -608,8 +608,7 @@ func (p *Process) getKProc() (*KinfoProc, error) {
func (p *Process) getKProcWithContext(ctx context.Context) (*KinfoProc, error) {
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
procK := KinfoProc{}
length := uint64(unsafe.Sizeof(procK))
length := uint64(unsafe.Sizeof(KinfoProc{}))
buf := make([]byte, length)
_, _, syserr := unix.Syscall6(
202, // unix.SYS___SYSCTL https://github.com/golang/sys/blob/76b94024e4b621e672466e8db3d7f084e7ddcad2/unix/zsysnum_darwin_amd64.go#L146

View File

@ -73,28 +73,25 @@ func (s *Storage) gc(sleep time.Duration) {
defer ticker.Stop()
var expired []string
for {
select {
case <-ticker.C:
ts := atomic.LoadUint32(&utils.Timestamp)
expired = expired[:0]
s.RLock()
for key, v := range s.data {
if v.e != 0 && v.e <= ts {
expired = append(expired, key)
}
for range ticker.C {
ts := atomic.LoadUint32(&utils.Timestamp)
expired = expired[:0]
s.RLock()
for key, v := range s.data {
if v.e != 0 && v.e <= ts {
expired = append(expired, key)
}
s.RUnlock()
s.Lock()
// Double-checked locking.
// We might have replaced the item in the meantime.
for i := range expired {
v := s.data[expired[i]]
if v.e != 0 && v.e <= ts {
delete(s.data, expired[i])
}
}
s.Unlock()
}
s.RUnlock()
s.Lock()
// Double-checked locking.
// We might have replaced the item in the meantime.
for i := range expired {
v := s.data[expired[i]]
if v.e != 0 && v.e <= ts {
delete(s.data, expired[i])
}
}
s.Unlock()
}
}

View File

@ -83,14 +83,14 @@ type bytespec struct {
type varmode int8
const (
constsize varmode = 0 // constant size (size bytes + uint8(varmode) objects)
extra8 = -1 // has uint8(p[1]) extra bytes
extra16 = -2 // has be16(p[1:]) extra bytes
extra32 = -3 // has be32(p[1:]) extra bytes
map16v = -4 // use map16
map32v = -5 // use map32
array16v = -6 // use array16
array32v = -7 // use array32
constsize varmode = -iota // constant size (size bytes + uint8(varmode) objects)
extra8 // has uint8(p[1]) extra bytes
extra16 // has be16(p[1:]) extra bytes
extra32 // has be32(p[1:]) extra bytes
map16v // use map16
map32v // use map32
array16v // use array16
array32v // use array32
)
func getType(v byte) Type {

View File

@ -778,7 +778,9 @@ func (mw *Writer) writeVal(v reflect.Value) error {
case reflect.Interface, reflect.Ptr:
if v.IsNil() {
mw.WriteNil()
if err := mw.WriteNil(); err != nil {
return err
}
}
return mw.writeVal(v.Elem())

View File

@ -94,7 +94,7 @@ func (e *Encoder) encode(v reflect.Value, dst map[string][]string) error {
// Encode struct pointer types if the field is a valid pointer and a struct.
if isValidStructPointer(v.Field(i)) {
e.encode(v.Field(i).Elem(), dst)
_ = e.encode(v.Field(i).Elem(), dst)
continue
}
@ -112,7 +112,7 @@ func (e *Encoder) encode(v reflect.Value, dst map[string][]string) error {
}
if v.Field(i).Type().Kind() == reflect.Struct {
e.encode(v.Field(i), dst)
_ = e.encode(v.Field(i), dst)
continue
}