go simple web server

试试go来一个简单的web server

 1 package main
 2 
 3 import (
 4     "fmt"
 5     "net/http"
 6 )
 7 
 8 // Default Request Handler
 9 func defaultHandler(w http.ResponseWriter, r *http.Request) {
10     fmt.Fprintf(w, "<h1>Hello %s!</h1>", r.URL.Path[1:])
11 }
12 
13 func main() {
14     http.HandleFunc("/", defaultHandler)
15     http.ListenAndServe(":8080", nil)
16 }

输入127.0.0.1:8080输出 hello word!

posted @ 2013-02-24 21:43  Gang.Wang  阅读(542)  评论(0编辑  收藏  举报