Changed default ApiReponse (just playing around)
This commit is contained in:
+28
-3
@@ -8,13 +8,38 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ApiResponse struct {
|
type ApiResponse struct {
|
||||||
Version int `json:"version"`
|
Method string `json:"method"`
|
||||||
Path string `json:"path"`
|
Url string `json:"url"`
|
||||||
|
Proto string `json:"proto"`
|
||||||
|
Header map[string]string `json:"header"`
|
||||||
|
Host string `json:"host"`
|
||||||
|
RemoteAddr string `json:"remoteAddr"`
|
||||||
|
Form map[string]string `json:"form"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
resp := ApiResponse{Path: "/v1", Version: 1}
|
var resp ApiResponse
|
||||||
|
|
||||||
|
resp.Method = r.Method
|
||||||
|
resp.Url = r.URL.String()
|
||||||
|
resp.Proto = r.Proto
|
||||||
|
resp.Header = make(map[string]string)
|
||||||
|
resp.Host = r.Host
|
||||||
|
resp.RemoteAddr = r.RemoteAddr
|
||||||
|
resp.Form = make(map[string]string)
|
||||||
|
|
||||||
|
for k, v := range r.Header {
|
||||||
|
resp.Header[k] = v[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := r.ParseForm(); err == nil {
|
||||||
|
for k, v := range r.Form {
|
||||||
|
resp.Form[k] = v[0]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Print(err)
|
||||||
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(resp)
|
b, err := json.Marshal(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user