-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
49 lines (39 loc) · 1.25 KB
/
generate.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"io/ioutil"
do "gopkg.in/godo.v2"
"gopkg.in/godo.v2/util"
)
var builderTemplate = `
package dat
//// DO NOT EDIT, auto-generated: godo builder-boilerplate
{{ range $idx, $builder := .builders }}
// Interpolate interpolates this builders sql.
func (b *{{$builder}}) Interpolate() (string, []interface{}, error) {
return interpolate(b)
}
// IsInterpolated determines if this builder will interpolate when
// Interpolate() is called.
func (b *{{$builder}}) IsInterpolated() bool {
return b.isInterpolated
}
// SetIsInterpolated sets whether this builder should interpolate.
func (b *{{$builder}}) SetIsInterpolated(enable bool) *{{$builder}} {
b.isInterpolated = enable
return b
}
{{ end }}
`
func generateTasks(p *do.Project) {
p.Task("builder-boilerplate", nil, func(c *do.Context) {
context := do.M{
"builders": []string{"CallBuilder", "DeleteBuilder", "InsectBuilder",
"InsertBuilder", "RawBuilder", "SelectBuilder", "SelectDocBuilder",
"UpdateBuilder", "UpsertBuilder"},
}
s, err := util.StrTemplate(builderTemplate, context)
c.Check(err, "Unalbe ")
ioutil.WriteFile("builders_generated.go", []byte(s), 0644)
c.Run("go fmt builders_generated.go")
}).Desc("Generates builder boilerplate code")
}