Skip to content

Instantly share code, notes, and snippets.

@suganoo
Created November 8, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suganoo/3e19c95e5d298c8fe75ee9c5dc53c8b3 to your computer and use it in GitHub Desktop.
Save suganoo/3e19c95e5d298c8fe75ee9c5dc53c8b3 to your computer and use it in GitHub Desktop.
httpのrequest
package main
import (
"fmt"
"net/http"
)
func body(w http.ResponseWriter, r *http.Request){
len := r.ContentLength
body := make([]byte, len)
r.Body.Read(body)
fmt.Fprintln(w, string(body))
}
func others(w http.ResponseWriter, r *http.Request){
fmt.Fprintln(w, r.Method)
fmt.Fprintln(w, r.Host)
fmt.Fprintln(w, r.Form)
fmt.Fprintln(w, r.Trailer)
fmt.Fprintln(w, r.RemoteAddr)
fmt.Fprintln(w, r.RequestURI)
}
func main() {
server := http.Server{
Addr : "127.0.0.1:8080",
}
http.HandleFunc("/body", body)
http.HandleFunc("/others", others)
server.ListenAndServe()
}
GET
localhost:8080
map[]
map[]
127.0.0.1:54480
/others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment