package main
import (
"fmt"
"net/http"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.URL.Path)
w.Write([]byte("Hello"))
}
func main() {
http.HandleFunc("/", indexHandler)
err := http.ListenAndServe(":9090", nil)
if err != nil {
fmt.Println(err)
}
}
学习了golang 之后 尝试的一个简单的web网站
我们看到上面的代码,要编写一个web服务器相比其他语言来说简单多了,只是需要调用http包的两个函数就ok了
不用像php,jsp一样非常麻烦,jsp还要将代码部署在服务器上,Go就不需要这么做应为Go直接监听了tcp端口,做了nginx做的事情
indexHandler 是一个函数,类似jsp中的controller。
golang调用系统命令
http://stackoverflow.com/questions/6182369/exec-a-shell-command-in-go