Changed default ApiReponse (just playing around)

This commit is contained in:
Robin Dittmar
2026-07-03 10:01:21 +02:00
parent 6febefc8e6
commit 4379f8bdda
+28 -3
View File
@@ -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 {