-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (41 loc) · 1.2 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
51
package main
import (
"flag"
"os"
"path/filepath"
"go.elara.ws/go-lemmy/cmd/gen/extractor"
"go.elara.ws/go-lemmy/cmd/gen/generator"
"go.elara.ws/logger"
"go.elara.ws/logger/log"
)
func init() {
log.Logger = logger.NewPretty(os.Stderr)
}
func main() {
jsonFile := flag.String("json-file", "lemmy.json", "Path to the JSON file generated from lemmy's docs")
outDir := flag.String("out-dir", "out", "Directory to write output in")
flag.Parse()
e, err := extractor.New(*jsonFile)
if err != nil {
log.Fatal("Error creating extractor").Err(err).Send()
}
routes, structs := e.Extract()
otf, err := os.Create(filepath.Join(*outDir, "types.gen.go"))
if err != nil {
log.Fatal("Error creating types output file").Err(err).Send()
}
defer otf.Close()
err = generator.NewStruct(otf, "lemmy").Generate(structs)
if err != nil {
log.Fatal("Error generating output routes file").Err(err).Send()
}
orf, err := os.Create(filepath.Join(*outDir, "routes.gen.go"))
if err != nil {
log.Fatal("Error creating routes output file").Err(err).Send()
}
defer orf.Close()
err = generator.NewRoutes(orf, "lemmy").Generate(routes)
if err != nil {
log.Fatal("Error generating output routes file").Err(err).Send()
}
}