@kjk1/

gobook template print

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.26557919129655394","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImxvZyIKCSJvcyIKCSJ0ZXh0L3RlbXBsYXRlIgopCgovLyA6c2hvdyBzdGFydApjb25zdCB0bXBsU3RyID0gYHByaW50OiAgIHt7IHByaW50IC5TdHIgLk51bSB9fQpwcmludGxuOiB7eyBwcmludGxuIC5TdHIgLk51bSB9fQpwcmludGY6ICB7eyBwcmludGYgIiVzICUjdiAlZCIgLlN0ciAuU3RyIC5OdW0gfX0KYAoKLy8gOnNob3cgZW5kCgpmdW5jIG1haW4oKSB7CgkvLyA6c2hvdyBzdGFydAoJdCA6PSB0ZW1wbGF0ZS5NdXN0KHRlbXBsYXRlLk5ldygicHJpbnQiKS5QYXJzZSh0bXBsU3RyKSkKCglkYXRhIDo9IHN0cnVjdCB7CgkJU3RyIHN0cmluZwoJCU51bSBpbnQKCX17CgkJU3RyOiAic3RyIiwKCQlOdW06IDgsCgl9CgllcnIgOj0gdC5FeGVjdXRlKG9zLlN0ZG91dCwgZGF0YSkKCWlmIGVyciAhPSBuaWwgewoJCWxvZy5GYXRhbGYoInQuRXhlY3V0ZSgpIGZhaWxlZCB3aXRoICclcydcbiIsIGVycikKCX0KCS8vIDpzaG93IGVuZAp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main

import (
	"log"
	"os"
	"text/template"
)

// :show start
const tmplStr = `print:   {{ print .Str .Num }}
println: {{ println .Str .Num }}
printf:  {{ printf "%s %#v %d" .Str .Str .Num }}
`

// :show end

func main() {
	// :show start
	t := template.Must(template.New("print").Parse(tmplStr))

	data := struct {
		Str string
		Num int
	}{
		Str: "str",
		Num: 8,
	}
	err := t.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}
	// :show end
}