[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [check/master] Expose host ip in JSON response



commit 21e22361dd76cbef423352cb9b84d9b7abe34440
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Thu Aug 14 05:54:43 2014 -0700

    Expose host ip in JSON response
---
 handlers.go |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/handlers.go b/handlers.go
index 3b220e0..179aa98 100644
--- a/handlers.go
+++ b/handlers.go
@@ -95,16 +95,23 @@ func RootHandler(Layout *template.Template, Exits *Exits, domain *gettext.Domain
 
 }
 
-type IPResp struct{ IsTor bool }
+type IPResp struct {
+	IsTor bool
+	IP    string
+}
 
 func APIHandler(Exits *Exits) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
 		w.Header().Set("Content-Type", "application/json")
-		var isTor bool
-		if host, err := GetHost(r); err == nil {
+		var (
+			err   error
+			isTor bool
+			host  string
+		)
+		if host, err = GetHost(r); err == nil {
 			_, isTor = Exits.IsTor(host)
 		}
-		ip, _ := json.Marshal(IPResp{isTor})
+		ip, _ := json.Marshal(IPResp{isTor, host})
 		w.Write(ip)
 	}
 }

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits