package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
"strings"
"unicode/utf8"
"sync"
"github.com/robfig/cron"
cpu "github.com/shirou/gopsutil/cpu"
"fmt"
)
const NumofResource = 4
// 구조체
type HostInfo struct {
Hostid string
}
var c *cron.Cron
var lastCPUTimes []cpu.TimesStat
func main() {
fmt.Println("1.main.go > main() start")
defer l4g.Close()
var err interface{}
lastCPUTimes, err = cpu.Times(false) //nil
fmt.Println("2.main.go > err", err)
fmt.Println("3.main.go > lastCPUTimes", lastCPUTimes)
if err != nil {
l4g.Error(err)
}
}
Ich weiß, dass die Hauptfunktion zuerst ausgeführt wird. Wir haben jedoch bestätigt, dass die Bibliothek cpu_windows.go zuerst ausgeführt wird. Warum?Go Hauptfunktion nicht zuerst
cpu_windows.go: Zeiten (bool) falsch
cpu_windows.go: common.ProcGetSystemTimes.Call 1
cpu_windows.go: Zeiten (bool) true
cpu_windows.go: Rückkehr perCPUTimes()
1.main.go: main() starten
cpu_windows.go: Zeiten (bool) falsch
cpu_windows.go: common.ProcGetSystemTimes.Call 1
2.main.go: err