host.go 255 B

123456789101112131415161718192021
  1. package sysx
  2. import (
  3. "os"
  4. "github.com/tal-tech/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. func Hostname() string {
  15. return hostname
  16. }