go-zero/core/sysx/host.go

23 lines
339 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package sysx
import (
"os"
"github.com/zeromicro/go-zero/core/stringx"
2020-07-26 17:09:05 +08:00
)
var hostname string
func init() {
var err error
hostname, err = os.Hostname()
if err != nil {
hostname = stringx.RandId()
}
2020-07-26 17:09:05 +08:00
}
2021-02-24 16:27:11 +08:00
// Hostname returns the name of the host, if no hostname, a random id is returned.
2020-07-26 17:09:05 +08:00
func Hostname() string {
return hostname
}