Here, We will learn how to get host name reported by the kernel in go. We can do it by using Hostname() function in os package in go golang.
Function prototype:
func Hostname() (name string, err error)
Return value:
Hostname() function in os package returns the host name reported by the kernel.
Example with code:
package main
import "fmt"
import "os"
func main() {
dir, err := os.Hostname()
fmt.Println(dir, ",", err)
}
Output:
C02YX14CLVDD , nil
To learn more about golang, Please refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/
https://golang.org/pkg/