host.go 335 B

12345678910111213141516171819202122
  1. package sysx
  2. import (
  3. "os"
  4. "git.i2edu.net/i2/go-zero/core/stringx"
  5. )
  6. var hostname string
  7. func init() {
  8. var err error
  9. hostname, err = os.Hostname()
  10. if err != nil {
  11. hostname = stringx.RandId()
  12. }
  13. }
  14. // Hostname returns the name of the host, if no hostname, a random id is returned.
  15. func Hostname() string {
  16. return hostname
  17. }