Commit fb9e37cd authored by Rob Pike's avatar Rob Pike

template: reverse order of arguments to Execute

In line with other functions such as Fprintf, put the
thing to be written first.

Apologies for the breakages this is sure to cause.

R=rsc, gri, adg, eds, r2, aam
CC=golang-dev
https://golang.org/cl/4169042
parent 2a81292a
......@@ -64,7 +64,7 @@ func init() {
}
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates[tmpl].Execute(p, w)
err := templates[tmpl].Execute(w, p)
if err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
}
......
......@@ -734,7 +734,7 @@ the <code>Execute</code> method on the appropriate <code>Template</code> from
<pre>
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates[tmpl].Execute(p, w)
err := templates[tmpl].Execute(w, p)
if err != nil {
http.Error(w, err.String(), http.StatusInternalServerError)
}
......
......@@ -2885,7 +2885,7 @@ func main() {
}
func QR(w http.ResponseWriter, req *http.Request) {
templ.Execute(req.FormValue("s"), w)
templ.Execute(w, req.FormValue("s"))
}
func UrlHtmlFormatter(w io.Writer, fmt string, v ...interface{}) {
......
......@@ -66,7 +66,7 @@ func FrontPage(w http.ResponseWriter, req *http.Request) {
if err != nil {
data = helloWorld
}
frontPage.Execute(data, w)
frontPage.Execute(w, data)
}
// Compile is an HTTP handler that reads Go source code from the request,
......@@ -123,7 +123,7 @@ func Compile(w http.ResponseWriter, req *http.Request) {
if *htmlOutput {
w.Write(out)
} else {
output.Execute(out, w)
output.Execute(w, out)
}
}
......@@ -132,9 +132,9 @@ func Compile(w http.ResponseWriter, req *http.Request) {
func error(w http.ResponseWriter, out []byte, err os.Error) {
w.WriteHeader(404)
if out != nil {
output.Execute(out, w)
output.Execute(w, out)
} else {
output.Execute(err.String(), w)
output.Execute(w, err.String())
}
}
......
......@@ -674,7 +674,7 @@ func servePage(w http.ResponseWriter, title, subtitle, query string, content []b
content,
}
if err := godocHTML.Execute(&d, w); err != nil {
if err := godocHTML.Execute(w, &d); err != nil {
log.Printf("godocHTML.Execute: %s", err)
}
}
......@@ -742,7 +742,7 @@ func serveHTMLDoc(w http.ResponseWriter, r *http.Request, abspath, relpath strin
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
var buf bytes.Buffer
if err := t.Execute(data, &buf); err != nil {
if err := t.Execute(&buf, data); err != nil {
log.Printf("%s.Execute: %s", name, err)
}
return buf.Bytes()
......
......@@ -381,7 +381,7 @@ func main() {
}
}
if err := packageText.Execute(info, os.Stdout); err != nil {
if err := packageText.Execute(os.Stdout, info); err != nil {
log.Printf("packageText.Execute: %s", err)
}
}
......@@ -75,7 +75,7 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) {
var buf bytes.Buffer
md := makedata{pkg, goFiles, cgoFiles, oFiles}
if err := makefileTemplate.Execute(&md, &buf); err != nil {
if err := makefileTemplate.Execute(&buf, &md); err != nil {
return nil, err
}
return buf.Bytes(), nil
......
......@@ -368,7 +368,7 @@ func main() {
if err != nil {
log.Exit(err)
}
err = t.Execute(data, os.Stdout)
err = t.Execute(os.Stdout, data)
if err != nil {
log.Exit(err)
}
......
......@@ -83,7 +83,7 @@ func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
server.Unlock()
sort.Sort(services)
err := debug.Execute(services, w)
err := debug.Execute(w, services)
if err != nil {
fmt.Fprintln(w, "rpc: error executing template:", err.String())
}
......
......@@ -972,7 +972,7 @@ func (t *Template) ParseFile(filename string) (err os.Error) {
// Execute applies a parsed template to the specified data object,
// generating output to wr.
func (t *Template) Execute(data interface{}, wr io.Writer) (err os.Error) {
func (t *Template) Execute(wr io.Writer, data interface{}) (err os.Error) {
// Extract the driver data.
val := reflect.NewValue(data)
defer checkError(&err)
......
......@@ -492,7 +492,7 @@ func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) {
t.Error("unexpected parse error: ", err)
continue
}
err = tmpl.Execute(s, &buf)
err = tmpl.Execute(&buf, s)
if test.err == "" {
if err != nil {
t.Error("unexpected execute error:", err)
......@@ -517,7 +517,7 @@ func TestMapDriverType(t *testing.T) {
t.Error("unexpected parse error:", err)
}
var b bytes.Buffer
err = tmpl.Execute(mp, &b)
err = tmpl.Execute(&b, mp)
if err != nil {
t.Error("unexpected execute error:", err)
}
......@@ -535,7 +535,7 @@ func TestMapNoEntry(t *testing.T) {
t.Error("unexpected parse error:", err)
}
var b bytes.Buffer
err = tmpl.Execute(mp, &b)
err = tmpl.Execute(&b, mp)
if err != nil {
t.Error("unexpected execute error:", err)
}
......@@ -552,7 +552,7 @@ func TestStringDriverType(t *testing.T) {
t.Error("unexpected parse error:", err)
}
var b bytes.Buffer
err = tmpl.Execute("hello", &b)
err = tmpl.Execute(&b, "hello")
if err != nil {
t.Error("unexpected execute error:", err)
}
......@@ -569,7 +569,7 @@ func TestTwice(t *testing.T) {
t.Error("unexpected parse error:", err)
}
var b bytes.Buffer
err = tmpl.Execute("hello", &b)
err = tmpl.Execute(&b, "hello")
if err != nil {
t.Error("unexpected parse error:", err)
}
......@@ -578,7 +578,7 @@ func TestTwice(t *testing.T) {
if s != expect {
t.Errorf("failed passing string as data: expected %q got %q", expect, s)
}
err = tmpl.Execute("hello", &b)
err = tmpl.Execute(&b, "hello")
if err != nil {
t.Error("unexpected parse error:", err)
}
......@@ -614,7 +614,7 @@ func TestCustomDelims(t *testing.T) {
continue
}
var b bytes.Buffer
err = tmpl.Execute("hello", &b)
err = tmpl.Execute(&b, "hello")
s := b.String()
if s != "template: hello"+ldelim+rdelim {
t.Errorf("failed delim check(%q %q) %q got %q", ldelim, rdelim, text, s)
......@@ -635,7 +635,7 @@ func TestVarIndirection(t *testing.T) {
if err != nil {
t.Fatal("unexpected parse error:", err)
}
err = tmpl.Execute(s, &buf)
err = tmpl.Execute(&buf, s)
if err != nil {
t.Fatal("unexpected execute error:", err)
}
......@@ -669,7 +669,7 @@ func TestReferenceToUnexported(t *testing.T) {
if err != nil {
t.Fatal("unexpected parse error:", err)
}
err = tmpl.Execute(u, &buf)
err = tmpl.Execute(&buf, u)
if err == nil {
t.Fatal("expected execute error, got none")
}
......@@ -749,7 +749,7 @@ func TestFormatters(t *testing.T) {
continue
}
buf := bytes.NewBuffer(nil)
err = tmpl.Execute(data, buf)
err = tmpl.Execute(buf, data)
if err != nil {
t.Error("unexpected Execute error: ", err)
continue
......
......@@ -49,7 +49,7 @@ func main() {
}
func run(t *template.Template, a interface{}, out io.Writer) {
if err := t.Execute(a, out); err != nil {
if err := t.Execute(out, a); err != nil {
panic(err)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment