Skip to content

Commit

Permalink
🧹 🐛 fix some warnings, go-ole on mac os (#2280)
Browse files Browse the repository at this point in the history
* 🧹 fix some warnings

* 🐛 fix go-ole on mac os
  • Loading branch information
jfcg authored Jan 1, 2023
1 parent 4d43db0 commit 9dfdea4
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build 386
// +build 386
//go:build 386 || arm
// +build 386 arm

package ole

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build amd64
// +build amd64
//go:build amd64 || arm64 || ppc64le || s390x
// +build amd64 arm64 ppc64le s390x

package ole

Expand Down
13 changes: 0 additions & 13 deletions internal/go-ole/variant_ppc64le.go

This file was deleted.

13 changes: 0 additions & 13 deletions internal/go-ole/variant_s390x.go

This file was deleted.

3 changes: 1 addition & 2 deletions internal/gopsutil/common/common_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
)

var invoke common.Invoker = common.Invoke{}
var _ common.Invoke

This comment has been minimized.

Copy link
@leonklingele

leonklingele Jan 1, 2023

Member

Why is this still required at all then?

This comment has been minimized.

Copy link
@jfcg

jfcg Jan 1, 2023

Author Contributor

not sure about the side effects of importing that package, so kept it as anon var


// Memory usage statistics. Total, Available and Used contain numbers of bytes
// for human consumption.
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/net/net_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
}

if pernic == false {
if !pernic {
return getIOCountersAll(ret)
}
return ret, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/gopsutil/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions internal/gopsutil/process/process_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])

This comment has been minimized.

Copy link
@leonklingele

leonklingele Jan 1, 2023

Member

Why ignore the error?

t += h * ClockTicks
h, err = strconv.Atoi(_t[1])
h, _ = strconv.Atoi(_t[1])

This comment has been minimized.

Copy link
@leonklingele

leonklingele Jan 1, 2023

Member

Why ignore the error?

t += h
return float64(t) / ClockTicks, nil
}
Expand Down Expand Up @@ -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
Expand Down
37 changes: 17 additions & 20 deletions internal/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.Unlock()
}
}
16 changes: 8 additions & 8 deletions internal/msgp/elsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion internal/msgp/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 2 additions & 2 deletions internal/schema/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

This comment has been minimized.

Copy link
@leonklingele

leonklingele Jan 1, 2023

Member

There should be a comment explaining why we ignore the error here.

continue
}

Expand All @@ -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
}

Expand Down

0 comments on commit 9dfdea4

Please sign in to comment.