From 257666439ae02e955848ad9384534767aee8240f Mon Sep 17 00:00:00 2001 From: wgroeneveld Date: Fri, 9 Apr 2021 14:23:16 +0200 Subject: [PATCH] get rid of text template silliness. This reduces binary by almost 2MB!? --- app/pingback/handler.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/pingback/handler.go b/app/pingback/handler.go index a3cccad..289e7b5 100644 --- a/app/pingback/handler.go +++ b/app/pingback/handler.go @@ -6,12 +6,10 @@ import ( "github.com/rs/zerolog/log" "github.com/wgroeneveld/go-jamming/app/mf" "github.com/wgroeneveld/go-jamming/app/webmention/receive" + "github.com/wgroeneveld/go-jamming/common" "github.com/wgroeneveld/go-jamming/rest" "io/ioutil" "net/http" - "text/template" - - "github.com/wgroeneveld/go-jamming/common" ) func HandlePost(conf *common.Config) http.HandlerFunc { @@ -40,29 +38,25 @@ func HandlePost(conf *common.Config) http.HandlerFunc { Conf: conf, } go receiver.Receive(wm) - pingbackSuccess(w, "Thanks, bro. Will process this soon, pinky swear!") + pingbackSuccess(w) } } -var successXml = ` +func pingbackSuccess(w http.ResponseWriter) { + xml := ` - {{ . }} + Thanks, bro. Will process this soon, pinky swear! - -` -// compile once, execute as many times as needed. -var successTpl, _ = template.New("success").Parse(successXml) - -func pingbackSuccess(w http.ResponseWriter, msg string) { +` w.WriteHeader(200) - successTpl.Execute(w, msg) + w.Write([]byte(xml)) } // according to the XML-RPC spec, always return a 200, but encode it into the XML.