-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvar.go
More file actions
39 lines (32 loc) · 770 Bytes
/
var.go
File metadata and controls
39 lines (32 loc) · 770 Bytes
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
package gg
import "io"
type ivar struct {
items *Group
}
func Var() *ivar {
i := &ivar{
items: newGroup("(", ")", "\n"),
}
i.items.omitWrapIf = func() bool {
// We only need to omit wrap while length == 1.
// NewIf length == 0, we need to keep it, or it will be invalid expr.
return i.items.length() == 1
}
return i
}
func (i *ivar) render(w io.Writer) {
writeString(w, "var ")
i.items.render(w)
}
func (i *ivar) AddField(name, value interface{}) *ivar {
i.items.append(field(name, value, "="))
return i
}
func (i *ivar) AddTypedField(name, typ, value interface{}) *ivar {
i.items.append(typedField(name, typ, value, "="))
return i
}
func (i *ivar) AddDecl(name, value interface{}) *ivar {
i.items.append(field(name, value, " "))
return i
}