如何在 Ubuntu 中正确安装和配置 Go 语言。有很多软件包可供选择,但是我需要安装哪些软件包以及之后我需要配置什么才能使用任何 Go 软件包而不会出现“找不到软件包”错误或任何其他基本错误那样。
我安装了该golang软件包,但是否需要安装任何其他软件包或配置其他内容?
作为示例,尝试运行以下命令:
package main
import (
"http"
"log"
)
func HelloServer(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Connection", "keep-alive")
w.Write([]byte("hello, world!\n"))
}
func main() {
http.HandleFunc("/", HelloServer)
log.Println("Serving at http://127.0.0.1:8080/")
http.ListenAndServe(":8080", nil)
}
Run Code Online (Sandbox Code Playgroud)