-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfield.go
More file actions
56 lines (50 loc) · 969 Bytes
/
field.go
File metadata and controls
56 lines (50 loc) · 969 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gg
import (
"io"
)
// ifield is used to represent a key-value pair.
//
// It could be used in:
// - struct decl
// - struct value
// - method receiver
// - function parameter
// - function result
// - ...
type ifield struct {
name Node
typ Node
value Node
separator string
extra string
}
func field(name, value interface{}, sep string) *ifield {
return &ifield{
name: parseNode(name),
value: parseNode(value),
separator: sep,
}
}
func typedField(name, typ, value interface{}, sep string) *ifield {
return &ifield{
name: parseNode(name),
typ: parseNode(typ),
value: parseNode(value),
separator: sep,
}
}
func (f *ifield) render(w io.Writer) {
f.name.render(w)
if f.typ != nil {
writeString(w, " ")
f.typ.render(w)
}
writeString(w, f.separator)
f.value.render(w)
if f.extra != "" {
writeString(w, " ", f.extra)
}
}
func (f *ifield) withExtra(extra string) {
f.extra = extra
}