GO获取主机名
package main
import (
"fmt"
"net/http"
"os"
)
func main() {
http.HandleFunc("/", home)
http.ListenAndServe(":80", nil)
}
func home(w http.ResponseWriter, r *http.Request) {
//fmt.Fprintf(w, "golang")
name, err := os.Hostname()
if err != nil {
panic(err)
}
fmt.Fprintf(w, name)
}
编译
go build -o hostx tets.go
//才5.9M很迷你
[root@dockser ~]# ls -lh hostx
-rwxr-xr-x 1 root root 5.9M 12月 6 01:3
GO获取主机名最先出现在Python成神之路。
共有 0 条评论