From 7dec1605707cfd1b6b8527121b1c0eb7f7c95196 Mon Sep 17 00:00:00 2001 From: 0xflotus <0xflotus@gmail.com> Date: Wed, 28 Oct 2020 14:07:41 +0100 Subject: [PATCH 1/3] added xml format --- api/get_ip.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/get_ip.go b/api/get_ip.go index 2020f50..81e14ea 100644 --- a/api/get_ip.go +++ b/api/get_ip.go @@ -7,6 +7,7 @@ package api import ( "encoding/json" + "encoding/xml" "fmt" "github.com/julienschmidt/httprouter" "github.com/rdegges/ipify-api/models" @@ -53,6 +54,11 @@ func GetIP(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { w.Header().Set("Content-Type", "application/javascript") fmt.Fprintf(w, callback+"("+string(jsonStr)+");") return + case "xml": + w.Header.Set("Content-Type", "application/xml") + xmlStr, _ := xml.MarshalIndent(models.IPAddress{ip}, " ", " ") + fmt.Fprintf(w, string(xmlStr)) + return } } From 9b5220de27a867988649dbd0cc15f0dd84054cfc Mon Sep 17 00:00:00 2001 From: 0xflotus <0xflotus@gmail.com> Date: Wed, 28 Oct 2020 14:36:50 +0100 Subject: [PATCH 2/3] added xml header --- api/get_ip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/get_ip.go b/api/get_ip.go index 81e14ea..188a4ff 100644 --- a/api/get_ip.go +++ b/api/get_ip.go @@ -57,7 +57,7 @@ func GetIP(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { case "xml": w.Header.Set("Content-Type", "application/xml") xmlStr, _ := xml.MarshalIndent(models.IPAddress{ip}, " ", " ") - fmt.Fprintf(w, string(xmlStr)) + fmt.Fprintf(w, xml.Header + string(xmlStr)) return } } From 3401e93901db05723c92dbb8c0e2b99194fe0914 Mon Sep 17 00:00:00 2001 From: 0xflotus <0xflotus@gmail.com> Date: Wed, 28 Oct 2020 14:37:56 +0100 Subject: [PATCH 3/3] Update get_ip.go --- api/get_ip.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/get_ip.go b/api/get_ip.go index 188a4ff..e27791a 100644 --- a/api/get_ip.go +++ b/api/get_ip.go @@ -55,7 +55,7 @@ func GetIP(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { fmt.Fprintf(w, callback+"("+string(jsonStr)+");") return case "xml": - w.Header.Set("Content-Type", "application/xml") + w.Header().Set("Content-Type", "application/xml") xmlStr, _ := xml.MarshalIndent(models.IPAddress{ip}, " ", " ") fmt.Fprintf(w, xml.Header + string(xmlStr)) return