Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run gofumpt and goimports #2662

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/go-ole/com.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func StringFromIID(iid *GUID) (str string, err error) {
}

// CreateInstance of single uninitialized object with GUID.
func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
func CreateInstance(clsid, iid *GUID) (unk *IUnknown, err error) {
if iid == nil {
iid = IID_IUnknown
}
Expand All @@ -195,7 +195,7 @@ func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
}

// GetActiveObject retrieves pointer to active object.
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
func GetActiveObject(clsid, iid *GUID) (unk *IUnknown, err error) {
if iid == nil {
iid = IID_IUnknown
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
}

// copyMemory moves location of a block of memory.
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
func copyMemory(dest, src unsafe.Pointer, length uint32) {
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
}

Expand All @@ -331,7 +331,7 @@ func GetUserDefaultLCID() (lcid uint32) {
// GetMessage in message queue from runtime.
//
// This function appears to block. PeekMessage does not block.
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
func GetMessage(msg *Msg, hwnd, MsgFilterMin, MsgFilterMax uint32) (ret int32, err error) {
r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
ret = int32(r0)
return
Expand Down
8 changes: 4 additions & 4 deletions internal/go-ole/com_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func StringFromIID(iid *GUID) (string, error) {
}

// CreateInstance of single uninitialized object with GUID.
func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
func CreateInstance(clsid, iid *GUID) (*IUnknown, error) {
return nil, NewError(E_NOTIMPL)
}

// GetActiveObject retrieves pointer to active object.
func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
func GetActiveObject(clsid, iid *GUID) (*IUnknown, error) {
return nil, NewError(E_NOTIMPL)
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
}

// copyMemory moves location of a block of memory.
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
func copyMemory(dest, src unsafe.Pointer, length uint32) {}

// GetUserDefaultLCID retrieves current user default locale.
func GetUserDefaultLCID() uint32 {
Expand All @@ -161,7 +161,7 @@ func GetUserDefaultLCID() uint32 {
// GetMessage in message queue from runtime.
//
// This function appears to block. PeekMessage does not block.
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
func GetMessage(msg *Msg, hwnd, MsgFilterMin, MsgFilterMax uint32) (int32, error) {
return int32(0), NewError(E_NOTIMPL)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/go-ole/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (c *Connection) Release() {

// Load COM object from list of programIDs or strings.
func (c *Connection) Load(names ...string) (errors []error) {
var tempErrors = make([]error, len(names))
var numErrors = 0
tempErrors := make([]error, len(names))
numErrors := 0
for _, name := range names {
err := c.Create(name)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions internal/go-ole/guid.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ var (
CLSID_COMTestScalarClass = NewGUID("{865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}")
)

const hextable = "0123456789ABCDEF"
const emptyGUID = "{00000000-0000-0000-0000-000000000000}"
const (
hextable = "0123456789ABCDEF"
emptyGUID = "{00000000-0000-0000-0000-000000000000}"
)

// GUID is Windows API specific GUID type.
//
Expand Down Expand Up @@ -177,7 +179,7 @@ func decodeHexUint16(src []byte) (value uint16, ok bool) {
return
}

func decodeHexByte64(s1 []byte, s2 []byte) (value [8]byte, ok bool) {
func decodeHexByte64(s1, s2 []byte) (value [8]byte, ok bool) {
var ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8 bool
value[0], ok1 = decodeHexByte(s1[0], s1[1])
value[1], ok2 = decodeHexByte(s1[2], s1[3])
Expand Down Expand Up @@ -269,7 +271,7 @@ func putByteHex(dst, src []byte) {
// IsEqualGUID compares two GUID.
//
// Not constant time comparison.
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
func IsEqualGUID(guid1, guid2 *GUID) bool {
return guid1.Data1 == guid2.Data1 &&
guid1.Data2 == guid2.Data2 &&
guid1.Data3 == guid2.Data3 &&
Expand Down
2 changes: 1 addition & 1 deletion internal/go-ole/idispatch_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}
if len(params) > 0 {
vargs = make([]VARIANT, len(params))
for i, v := range params {
//n := len(params)-i-1
// n := len(params)-i-1
n := len(params) - i - 1
VariantInit(&vargs[n])
switch vv := v.(type) {
Expand Down
2 changes: 1 addition & 1 deletion internal/go-ole/oleutil/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func dispRelease(this *ole.IUnknown) int32 {
return pthis.ref
}

func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen, lcid int, pdisp []int32) uintptr {
pthis := (*stdDispatch)(unsafe.Pointer(this))
names := make([]string, len(wnames))
for i := 0; i < len(names); i++ {
Expand Down
2 changes: 1 addition & 1 deletion internal/go-ole/safearray_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
//
// AKA: SafeArrayCopyData in Windows API.
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
func safeArrayCopyData(original, duplicate *SafeArray) error {
return NewError(E_NOTIMPL)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/go-ole/safearray_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var (
procSafeArrayUnaccessData = modoleaut32.NewProc("SafeArrayUnaccessData")
procSafeArrayUnlock = modoleaut32.NewProc("SafeArrayUnlock")
procSafeArrayPutElement = modoleaut32.NewProc("SafeArrayPutElement")
//procSafeArrayRedim = modoleaut32.NewProc("SafeArrayRedim") // TODO
//procSafeArraySetIID = modoleaut32.NewProc("SafeArraySetIID") // TODO
// procSafeArrayRedim = modoleaut32.NewProc("SafeArrayRedim") // TODO
// procSafeArraySetIID = modoleaut32.NewProc("SafeArraySetIID") // TODO
procSafeArrayGetRecordInfo = modoleaut32.NewProc("SafeArrayGetRecordInfo")
procSafeArraySetRecordInfo = modoleaut32.NewProc("SafeArraySetRecordInfo")
)
Expand Down Expand Up @@ -102,7 +102,7 @@ func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
//
// AKA: SafeArrayCopyData in Windows API.
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
func safeArrayCopyData(original, duplicate *SafeArray) (err error) {
err = convertHresultToError(
procSafeArrayCopyData.Call(
uintptr(unsafe.Pointer(original)),
Expand Down
2 changes: 1 addition & 1 deletion internal/go-ole/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func lpOleStrLen(p *uint16) (length int64) {
}

// convertHresultToError converts syscall to error, if call is unsuccessful.
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
func convertHresultToError(hr, r2 uintptr, ignore error) (err error) {
if hr != 0 {
err = NewError(hr)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/gopsutil/common/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ type coder struct {
buf []byte
}

type decoder coder
type encoder coder
type (
decoder coder
encoder coder
)

func (d *decoder) uint8() uint8 {
x := d.buf[0]
Expand Down
3 changes: 1 addition & 2 deletions internal/gopsutil/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ var ErrNotImplementedError = errors.New("not implemented yet")
// ReadFile reads contents from a file
func ReadFile(filename string) (string, error) {
content, err := os.ReadFile(filename)

if err != nil {
return "", err
}
Expand Down Expand Up @@ -320,7 +319,7 @@ func PathExists(filename string) bool {
}

// GetEnv retrieves the environment variable key. If it does not exist it returns the default.
func GetEnv(key string, dfault string, combineWith ...string) string {
func GetEnv(key, dfault string, combineWith ...string) string {
value := os.Getenv(key)
if value == "" {
value = dfault
Expand Down
4 changes: 1 addition & 3 deletions internal/gopsutil/common/common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func NumProcs() (uint64, error) {
}

func BootTimeWithContext(ctx context.Context) (uint64, error) {

system, role, err := Virtualization()
if err != nil {
return 0, err
Expand Down Expand Up @@ -192,7 +191,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
if PathExists(filepath.Join(filename, "self", "status")) {
contents, err := ReadLines(filepath.Join(filename, "self", "status"))
if err == nil {

if StringsContains(contents, "s_context:") ||
StringsContains(contents, "VxID:") {
system = "linux-vserver"
Expand Down Expand Up @@ -241,7 +239,7 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
return system, role, nil
}

func GetOSRelease() (platform string, version string, err error) {
func GetOSRelease() (platform, version string, err error) {
contents, err := ReadLines(HostEtc("os-release"))
if err != nil {
return "", "", nil // return empty
Expand Down
5 changes: 3 additions & 2 deletions internal/gopsutil/common/common_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
"syscall"
"unsafe"

"github.com/gofiber/fiber/v2/internal/wmi"
"golang.org/x/sys/windows"

"github.com/gofiber/fiber/v2/internal/wmi"
)

// for double values
Expand Down Expand Up @@ -156,7 +157,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
if err != nil {
return nil, err
}
var counter = Win32PerformanceCounter{
counter := Win32PerformanceCounter{
Query: query,
PostName: postName,
CounterName: counterName,
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/common/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// Sleep awaits for provided interval.
// Can be interrupted by context cancelation.
func Sleep(ctx context.Context, interval time.Duration) error {
var timer = time.NewTimer(interval)
timer := time.NewTimer(interval)
select {
case <-ctx.Done():
if !timer.Stop() {
Expand Down
6 changes: 4 additions & 2 deletions internal/gopsutil/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ type lastPercent struct {
lastPerCPUTimes []TimesStat
}

var lastCPUPercent lastPercent
var invoke common.Invoker = common.Invoke{}
var (
lastCPUPercent lastPercent
invoke common.Invoker = common.Invoke{}
)

func init() {
lastCPUPercent.Lock()
Expand Down
1 change: 0 additions & 1 deletion internal/gopsutil/cpu/cpu_darwin_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ func allCPUTimes() ([]TimesStat, error) {
}

return []TimesStat{c}, nil

}
21 changes: 12 additions & 9 deletions internal/gopsutil/cpu/cpu_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import (
"strings"
"unsafe"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
"golang.org/x/sys/unix"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
)

var ClocksPerSec = float64(128)
var cpuMatch = regexp.MustCompile(`^CPU:`)
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
var cpuEnd = regexp.MustCompile(`^Trying to mount root`)
var cpuTimesSize int
var emptyTimes cpuTimes
var (
ClocksPerSec = float64(128)
cpuMatch = regexp.MustCompile(`^CPU:`)
originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
cpuEnd = regexp.MustCompile(`^Trying to mount root`)
cpuTimesSize int
emptyTimes cpuTimes
)

func init() {
getconf, err := exec.LookPath("getconf")
Expand Down
23 changes: 13 additions & 10 deletions internal/gopsutil/cpu/cpu_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import (
"strings"
"unsafe"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
"golang.org/x/sys/unix"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
)

var ClocksPerSec = float64(128)
var cpuMatch = regexp.MustCompile(`^CPU:`)
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
var cpuEnd = regexp.MustCompile(`^Trying to mount root`)
var cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`)
var cpuTimesSize int
var emptyTimes cpuTimes
var (
ClocksPerSec = float64(128)
cpuMatch = regexp.MustCompile(`^CPU:`)
originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
cpuEnd = regexp.MustCompile(`^Trying to mount root`)
cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`)
cpuTimesSize int
emptyTimes cpuTimes
)

func init() {
getconf, err := exec.LookPath("getconf")
Expand Down
4 changes: 2 additions & 2 deletions internal/gopsutil/cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Times(percpu bool) ([]TimesStat, error) {

func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
filename := common.HostProc("stat")
var lines = []string{}
lines := []string{}
if percpu {
statlines, err := common.ReadLines(filename)
if err != nil || len(statlines) < 2 {
Expand Down Expand Up @@ -315,7 +315,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
}
// physical cores
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L621-L629
var threadSiblingsLists = make(map[string]bool)
threadSiblingsLists := make(map[string]bool)
if files, err := filepath.Glob(common.HostSys("devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list")); err == nil {
for _, file := range files {
lines, err := common.ReadLines(file)
Expand Down
5 changes: 3 additions & 2 deletions internal/gopsutil/cpu/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"strings"
"syscall"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
"golang.org/x/sys/unix"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
)

// sys/sched.h
Expand Down Expand Up @@ -117,7 +118,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
j *= 2
}

var cpuTimes = make([]int32, CPUStates)
cpuTimes := make([]int32, CPUStates)
var mib []int32
if percpu {
mib = []int32{CTLKern, KernCptime2, int32(j)}
Expand Down
2 changes: 1 addition & 1 deletion internal/gopsutil/cpu/cpu_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
user := make(map[float64]float64)
kern := make(map[float64]float64)
iowt := make(map[float64]float64)
//swap := make(map[float64]float64)
// swap := make(map[float64]float64)
kstatSysOut, err := invoke.CommandWithContext(ctx, kstatSys, "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
if err != nil {
return nil, fmt.Errorf("cannot execute kstat: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/gopsutil/cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"fmt"
"unsafe"

"golang.org/x/sys/windows"

"github.com/gofiber/fiber/v2/internal/gopsutil/common"
"github.com/gofiber/fiber/v2/internal/wmi"
"golang.org/x/sys/windows"
)

var (
Expand Down
Loading
Loading