forked from danielvladco/go-proto-gql
/
models.go
72 lines (58 loc) · 1.25 KB
/
models.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
61
62
63
64
65
66
67
68
69
70
71
72
package plugin
import (
"sort"
"github.com/gogo/protobuf/protoc-gen-gogo/descriptor"
)
type ModelDescriptor struct {
BuiltIn bool
PackageDir string
TypeName string
UsedAsInput bool
Index int
OneofTypes map[string]struct{}
packageName string
originalPackage string
}
type Method struct {
Name string
InputType string
OutputType string
Phony bool
ServiceIndex int
Index int
*descriptor.MethodDescriptorProto
*descriptor.ServiceDescriptorProto
}
type Methods []*Method
func (ms Methods) NameExists(name string) bool {
for _, m := range ms {
if m.Name == name {
return true
}
}
return false
}
type Type struct {
*descriptor.DescriptorProto
*descriptor.EnumDescriptorProto
ModelDescriptor
}
type TypeMapList []*TypeMapEntry
func (t TypeMapList) Len() int { return len(t) }
func (t TypeMapList) Less(i, j int) bool { return t[i].Key < t[j].Key }
func (t TypeMapList) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func TypeMap2List(t map[string]*Type) (m TypeMapList) {
for key, val := range t {
m = append(m, &TypeMapEntry{Key: key, Value: val})
}
sort.Sort(m)
return
}
type TypeMapEntry struct {
Key string
Value *Type
}
type OneofRef struct {
Parent *Type
Index int32
}