12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
网站建设 时间:2024-11-27 18:39:34
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
GO使用http.HandleFunc()方法搭建一个网站程序,具体方法如下:1.使用http.HandleFunc()方法获取参数,并保存为 hello.go文件;package mainimport ("io""log""net/http")func hell
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
GO使用http.HandleFunc()方法搭建一个网站程序,具体方法如下:
1.使用http.HandleFunc()方法获取参数,并保存为 hello.go文件;
package main
import (
"io"
"log"
"net/http"
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello, world!")
}
func main() {
http.HandleFunc("/hello", helloHandler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}
2.编译 hello.go文件;
$ go run hello.go
3.最后,在浏览器中访问http://localhost:8080/hello即可;
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19