服务端
写法1
package main
import (
"net/http"
)
func main() {
svrMux := http.NewServeMux()
svrMux.HandleFunc("/", rootHandler)
if err := http.ListenAndServe(":80", svrMux); err != nil {
return
}
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(getRemoteAddr(r)))
}
func getRemoteAddr(r *http.Request) string {
return r.RemoteAddr + "\n"
}