用 net/http 包可以快速起一个 web 服务
点击查看代码
package main
import (
"fmt"
"net/http"
)
func helloWorld(w http.ResponseWriter, req *http.Request) {
_, err := fmt.Fprintf(w, "Hello world!")
if err != nil {
fmt.Println("code: 500")
}
}
func main() {
http.HandleFunc("/hello",helloWorld)
err := http.ListenAndServe("0.0.0.0:9000", nil)
if err != nil {
fmt.Println("Listen is failed", err)
}
}