golang 搭建 web服务

go语言可以很简单的搭建起一个web服务,重要的只需要仅仅几行,代码如下:
package main

import (
"fmt"
"log"
"net/http"
)

func main() {
http.HandleFunc("/", HelloWeb)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("error:", err)
}
}

func HelloWeb(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Fprintf(w, "hello world!!")
}

posted @ 2015-06-04 22:28  菜B  阅读(401)  评论(0编辑  收藏  举报