~tsileo/blobstash

ref: b178995e346d blobstash/pkg/luascripts/luascripts.go -rw-r--r-- 476 bytes
b178995eThomas Sileo vendor: update deps 2 years ago
                                                                                
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
package luascripts // import "a4.io/blobstash/pkg/luascripts"

import (
	"bytes"
	"fmt"
	"text/template"
)

func Get(name string) string {
	dat, ok := files[name]
	if !ok {
		panic(fmt.Sprintf("missing file %s", name))
	}
	return dat
}

type Ctx map[string]interface{}

func Tpl(name string, ctx Ctx) string {
	tpl := template.Must(template.New("").Parse(Get(name)))
	var buf bytes.Buffer
	if err := tpl.Execute(&buf, ctx); err != nil {
		panic(err)
	}
	return buf.String()
}