-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (41 loc) · 1.06 KB
/
main.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
package main
import (
"log"
)
func main() {
conf, err := initConfig()
if err != nil {
log.Fatalf("could not init config: %v", err)
}
pkg, typ, err := parseType(conf.Pkg, conf.Type)
if err != nil {
log.Fatalf("cannot parse type %s: %v", conf.Type, err)
}
parseParams := parseFieldsParams{
format: conf.Format,
tag: conf.Tag,
tagRegex: conf.TagRegex,
tagFormat: conf.TagFormat,
tagStrict: conf.TagStrict,
embedded: conf.Embedded,
excluded: conf.Excluded,
}
fields, err := parseFields(typ, parseParams, 0)
if err != nil {
log.Fatalf("cannot parse fields for type %s: %v", conf.Type, err)
}
if len(fields) == 0 {
log.Fatalf("no fields found for type %s", conf.Type)
}
output, err := generateOutput(pkg, conf.Type, conf.Suffix, conf.TemplateFilename, fields)
if err != nil {
log.Fatalf("cannot generate output: %v", err)
}
if len(output) == 0 {
log.Fatalf("no output generated")
}
err = writeToFile(output, conf.OutputFilename)
if err != nil {
log.Fatalf("cannot write to file %s: %v", conf.OutputFilename, err)
}
}