get rid of text template silliness. This reduces binary by almost 2MB!?

This commit is contained in:
Wouter Groeneveld 2021-04-09 14:23:16 +02:00
parent ddd465ce92
commit 257666439a
1 changed files with 7 additions and 13 deletions

View File

@ -6,12 +6,10 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/wgroeneveld/go-jamming/app/mf" "github.com/wgroeneveld/go-jamming/app/mf"
"github.com/wgroeneveld/go-jamming/app/webmention/receive" "github.com/wgroeneveld/go-jamming/app/webmention/receive"
"github.com/wgroeneveld/go-jamming/common"
"github.com/wgroeneveld/go-jamming/rest" "github.com/wgroeneveld/go-jamming/rest"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"text/template"
"github.com/wgroeneveld/go-jamming/common"
) )
func HandlePost(conf *common.Config) http.HandlerFunc { func HandlePost(conf *common.Config) http.HandlerFunc {
@ -40,29 +38,25 @@ func HandlePost(conf *common.Config) http.HandlerFunc {
Conf: conf, Conf: conf,
} }
go receiver.Receive(wm) go receiver.Receive(wm)
pingbackSuccess(w, "Thanks, bro. Will process this soon, pinky swear!") pingbackSuccess(w)
} }
} }
var successXml = `<?xml version="1.0" encoding="UTF-8"?> func pingbackSuccess(w http.ResponseWriter) {
xml := `<?xml version="1.0" encoding="UTF-8"?>
<methodResponse> <methodResponse>
<params> <params>
<param> <param>
<value> <value>
<string> <string>
{{ . }} Thanks, bro. Will process this soon, pinky swear!
</string> </string>
</value> </value>
</param> </param>
</params> </params>
</methodResponse> </methodResponse>`
`
// 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) 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. // according to the XML-RPC spec, always return a 200, but encode it into the XML.