From f0bed47d1ebf5c3f5956843f80149dd81296e636 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Mon, 19 Nov 2012 19:50:49 +0100 Subject: [PATCH] Render HTML template if User-Agent is a regular browser --- ifconfig.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ifconfig.go b/ifconfig.go index 988f211..9bd8417 100644 --- a/ifconfig.go +++ b/ifconfig.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "html/template" "io" "log" "net" @@ -9,6 +10,10 @@ import ( "regexp" ) +type Client struct { + Host string +} + func isCli(userAgent string) bool { match, _ := regexp.MatchString("^(?i)(curl|wget|fetch\\slibfetch)\\/.*$", userAgent) @@ -31,7 +36,9 @@ func handler(w http.ResponseWriter, req *http.Request) { if isCli(req.UserAgent()) { io.WriteString(w, fmt.Sprintf("%s\n", host)) } else { - // XXX: Render HTML + t, _ := template.ParseFiles("index.html") + client := &Client{Host: host} + t.Execute(w, client) } }