hello Go!!
创建环境(可CSDN自行搜索),新建文件夹,新建文件main.go
package main
import (
"fmt"
"net/http"
)
func handler(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintf(writer, "hello Go!!,%s!", request.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
在当前目录执行 go run main.在浏览器中输入@http://127.0.0.1:8080/,按回车,可见下图:
至此,第一个示例完成!!