// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package osimport ()func hostname() ( string, error) {// Try uname first, as it's only one system call and reading // from /proc is not allowed on Android.varsyscall.Utsname = syscall.Uname(&)var [512]byte// Enough for a DNS name.for , := range .Nodename[:] { [] = uint8()if == 0 { = string([:])break } }// If we got a name and it's not potentially truncated // (Nodename is 65 bytes), return it.if == nil && len() > 0 && len() < 64 {return , nil }ifruntime.GOOS == "android" {if != "" {return , nil }return"localhost", nil } , := Open("/proc/sys/kernel/hostname")if != nil {return"", }defer .Close() , := .Read([:])if != nil {return"", }if > 0 && [-1] == '\n' { -- }returnstring([:]), nil}
The pages are generated with Goldsv0.7.3-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.