hostname.go 351 B

123456789101112131415
  1. package device
  2. import "os"
  3. var hostname string
  4. // GetHostname returns the hostname of the current device. Caches the hostname
  5. // between calls to ensure this is performant. Returns a blank string in case
  6. // that the hostname cannot be identified.
  7. func GetHostname() string {
  8. if hostname == "" {
  9. hostname, _ = os.Hostname()
  10. }
  11. return hostname
  12. }