github.com/lingyao2333/mo-zero@v1.4.1/core/sysx/host.go (about)

     1  package sysx
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/lingyao2333/mo-zero/core/stringx"
     7  )
     8  
     9  var hostname string
    10  
    11  func init() {
    12  	var err error
    13  	hostname, err = os.Hostname()
    14  	if err != nil {
    15  		hostname = stringx.RandId()
    16  	}
    17  }
    18  
    19  // Hostname returns the name of the host, if no hostname, a random id is returned.
    20  func Hostname() string {
    21  	return hostname
    22  }