-
Notifications
You must be signed in to change notification settings - Fork 27
/
tl_gen_init.go
48 lines (36 loc) · 1009 Bytes
/
tl_gen_init.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
package gen
import (
"sort"
"github.com/dave/jennifer/jen"
)
var tlPackagePath = "github.com/amarnathcjd/gogram/internal/encoding/tl"
var errorsPackagePath = "github.com/pkg/errors"
func (g *Generator) generateInit(file *jen.File) {
structs, enums := g.getAllConstructors()
initFunc := jen.Func().Id("init").Params().Block(
g.createInitStructs(structs...),
jen.Line(),
g.createInitEnums(enums...),
)
file.Add(initFunc)
}
func (*Generator) createInitStructs(itemNames ...string) jen.Code {
sort.Strings(itemNames)
structs := make([]jen.Code, len(itemNames))
for i, item := range itemNames {
structs[i] = jen.Op("&").Id(item).Block()
}
return jen.Qual(tlPackagePath, "RegisterObjects").Call(
structs...,
)
}
func (*Generator) createInitEnums(itemNames ...string) jen.Code {
sort.Strings(itemNames)
enums := make([]jen.Code, len(itemNames))
for i, item := range itemNames {
enums[i] = jen.Id(item)
}
return jen.Qual(tlPackagePath, "RegisterEnums").Call(
enums...,
)
}