-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlazyfield.go
60 lines (44 loc) · 1.01 KB
/
lazyfield.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
50
51
52
53
54
55
56
57
58
59
60
package meta
import (
"errors"
"fmt"
"github.com/davyxu/golexer"
)
type lazyField struct {
typeName string
mainIndexName string
fd *FieldDescriptor
d *Descriptor
tp golexer.TokenPos
miss bool
}
func newLazyField(typeName string, fd *FieldDescriptor, d *Descriptor, tp golexer.TokenPos) *lazyField {
return &lazyField{typeName: typeName,
fd: fd,
d: d,
tp: tp}
}
func (self *lazyField) resolve(pass int) (bool, error) {
self.fd.Type, self.fd.Complex = self.fd.parseType(self.typeName)
if self.fd.Type == FieldType_None {
if pass > 1 {
fmt.Println(self.tp.String())
return true, errors.New("type not found: " + self.typeName)
} else {
self.miss = true
return true, nil
}
}
if self.mainIndexName != "" {
if indexFd, ok := self.fd.Complex.FieldByName[self.mainIndexName]; ok {
self.fd.MainIndex = indexFd
} else {
if pass > 1 {
return true, errors.New("Main index not found:" + self.mainIndexName)
} else {
return true, nil
}
}
}
return false, nil
}