如何在Go中獲取節點的主機名?

2021-10-08 15:55:05 字數 879 閱讀 8724

in go lang, how to get the hostname of the node?

在go lang中,如何獲取節點的主機名?

ingo, you can use theos.hostname()function to get the hostname of the node.

go中,可以使用os.hostname()函式獲取節點的主機名。

func hostname() (namestring, err error)
hostname returns the host name reported by the kernel.

主機名返回核心報告的主機名。

one example is as follows. themain.gosource code:

乙個例子如下。main.go源**:

package main

import (

"fmt"

"os"

)func main()

fmt.println("hostname:", name)

}

run it:

執行:

$ go run main.go

hostname: host001

answered by dtivl.

dtivl回答。

翻譯自:

如何在Linux中顯示和設定主機名

隨著連線到網路的計算機數量越來越多,每一台計算機都需要有乙個屬性來區別於其它計算機。和現實世界中的人一樣,計算機也有乙個叫做hostname 主機名 的屬性。什麼是hostname 從它的操作手冊來看,hostname是用來顯示系統的dns名字以及為了顯示和設定它的主機名或者nis網域名稱名字。所以...

如何在CentOS 7上修改主機名

在centos中,有三種定義的主機名 靜態的 static 瞬態的 transient 和靈活的 pretty 靜態 主機名也稱為核心主機名,是系統在啟動時從 etc hostname自動初始化的主機名。瞬態 主機名是在系統執行時臨時分配的主機名,例如,通過dhcp或mdns伺服器分配。靜態主機名和...

如何在CentOS 7上修改主機名

在centos中,有三種定義的主機名 靜態的 static 瞬態的 transient 和靈活的 pretty 靜態 主機名也稱為核心主機名,是系統在啟動時從 etc hostname自動初始化的主機名。瞬態 主機名是在系統執行時臨時分配的主機名,例如,通過dhcp或mdns伺服器分配。靜態主機名和...