Use static initialisation for invoke instances, instead of init funcs

The order of init function execution is dependant on the order that the
source files are passed to the compiler. This causes issues when
building under other build systems, such as bazel or buck, as they are
not guarenteed to maintain the same file order as the default go tool.
pull/502/head
Laurie Clark-Michalek 7 years ago
parent 6b5767f15e
commit 413cb32b6c

@ -54,10 +54,9 @@ type lastPercent struct {
} }
var lastCPUPercent lastPercent var lastCPUPercent lastPercent
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() { func init() {
invoke = common.Invoke{}
lastCPUPercent.Lock() lastCPUPercent.Lock()
lastCPUPercent.lastCPUTimes, _ = Times(false) lastCPUPercent.lastCPUTimes, _ = Times(false)
lastCPUPercent.lastPerCPUTimes, _ = Times(true) lastCPUPercent.lastPerCPUTimes, _ = Times(true)

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type UsageStat struct { type UsageStat struct {
Path string `json:"path"` Path string `json:"path"`

@ -10,11 +10,7 @@ import (
var ErrDockerNotAvailable = errors.New("docker not available") var ErrDockerNotAvailable = errors.New("docker not available")
var ErrCgroupNotAvailable = errors.New("cgroup not available") var ErrCgroupNotAvailable = errors.New("cgroup not available")
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type CgroupMemStat struct { type CgroupMemStat struct {
ContainerID string `json:"containerID"` ContainerID string `json:"containerID"`

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
// A HostInfoStat describes the host status. // A HostInfoStat describes the host status.
// This is not in the psutil but it useful. // This is not in the psutil but it useful.

@ -6,11 +6,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type AvgStat struct { type AvgStat struct {
Load1 float64 `json:"load1"` Load1 float64 `json:"load1"`

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

@ -12,11 +12,7 @@ import (
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type IOCountersStat struct { type IOCountersStat struct {
Name string `json:"name"` // interface name Name string `json:"name"` // interface name

@ -11,11 +11,7 @@ import (
"github.com/shirou/gopsutil/mem" "github.com/shirou/gopsutil/mem"
) )
var invoke common.Invoker var invoke common.Invoker = common.Invoke{}
func init() {
invoke = common.Invoke{}
}
type Process struct { type Process struct {
Pid int32 `json:"pid"` Pid int32 `json:"pid"`

Loading…
Cancel
Save