Slide 18
Slide 18 text
© DMM
全体のコード生成イメージ
host path method
query
param
reqbody response
host path method
query
param
reqbody response
host path method
query
param
reqbody response
host
path method
query
param
reqbody response
method
query
param
reqbody response
path method
query
param
reqbody response
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
body, _ := stringify(r.Body)
if r.Method == "GET" {
if q, _ := stringifyUrlValues(r.URL.Query()); q == "{}" {
if body == "{\"token\":\"abc\"}" {
rw.WriteHeader(200)
fmt.Fprint(rw, "{\"foo\":\"bar\"}")
return
}
}
}
if r.Method == "POST" {
if q, _ := stringifyUrlValues(r.URL.Query()); q == "{}" {
if body == "{\"token\":\"abc\"}" {
rw.WriteHeader(200)
fmt.Fprint(rw, "{\"foo\":\"bar\"}")
return
}
}
}
})
mux.HandleFunc("/hoge", func(rw http.ResponseWriter, r *http.Request) {
body, _ := stringify(r.Body)
if r.Method == "GET" {
if q, _ := stringifyUrlValues(r.URL.Query()); q == "{}" {
if body == "{\"token\":\"abc\"}" {
rw.WriteHeader(200)
fmt.Fprint(rw, "{\"foo\":\"bar\"}")
return
}
}
}
})
溜まっていく
深さ優先でツリーを巡回して生成