因为一直在做WEB程序,所以更关注WEB界的发展,这里就用GO做了一个简单的WEB服务器,直接看例子吧
package main import ( "fmt" "net/http" ) // Default Request Handler func defaultHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "<h1>Hello World %s!</h1>", r.URL.Path[1:]) } func getHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "<h1>Hello World Every Guys!</h1>") } func main() { http.HandleFunc("/", defaultHandler) http.HandleFunc("/get", getHandler) http.ListenAndServe(":8080", nil) }好了,编译后,在浏览器输入 127.0.0.1:8080 体验功能吧
有疑问加站长微信联系(非本文作者)