在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
package main import ( "fmt" "net/http" "os" ) func indexHandler(w http.ResponseWriter, r *http.Request) { fmt.Println("打印Header参数列表:") if len(r.Header) > 0 { for k,v := range r.Header { fmt.Printf("%s=%s\n", k, v[0]) w.Header().Set(k,v[0]) } } VERS := os.Getenv("Version") fmt.Printf("变量Version: %s\n",VERS) w.Header().Set("Version",VERS) fmt.Printf("客户端IP: %s\n",r.RemoteAddr) fmt.Println("打印response header参数列表: ") fmt.Println(w.Header()) fmt.Fprintln(w, "hello world") } func healthz(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintln(w, "OK") } func main() { http.HandleFunc("/", indexHandler) http.HandleFunc("/healthz",healthz) http.ListenAndServe(":8000", nil) }
|
请发表评论