finclip-app-manager/vendor/gitlab.finogeeks.club/finclip-backend/apm/os_util.go

55 lines
805 B
Go
Raw Permalink Normal View History

2023-11-02 18:36:36 +08:00
package apm
import (
"net"
"os"
"runtime"
"strconv"
)
func ProcessNo() string {
if os.Getpid() > 0 {
return strconv.Itoa(os.Getpid())
}
return ""
}
func HostName() string {
if hs, err := os.Hostname(); err == nil {
return hs
}
return "unknown"
}
func OSName() string {
return runtime.GOOS
}
func AllIPV4() (ipv4s []string) {
adders, err := net.InterfaceAddrs()
if err != nil {
return
}
for _, addr := range adders {
if ipNet, ok := addr.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ipv4 := ipNet.IP.String()
if ipv4 == "127.0.0.1" || ipv4 == "localhost" {
continue
}
ipv4s = append(ipv4s, ipv4)
}
}
}
return
}
func IPV4() string {
ipv4s := AllIPV4()
if len(ipv4s) > 0 {
return ipv4s[0]
}
return "no-hostname"
}