webserver.go
package main
import(
"net/http"
)
func tList(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type", "application/json;charset=utf-8")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Write([]byte(`{"data":{"tlist":[{"id":1, "name":"sunjingming"},{"id":2, "name":"liulll"}]}}`))
}
func main() {
http.HandleFunc("/", tList)
http.ListenAndServe(":8000", nil)
}
执行: go run webserver.go