-
Notifications
You must be signed in to change notification settings - Fork 0
/
protoc-gen-blaze.go
69 lines (60 loc) · 1.51 KB
/
protoc-gen-blaze.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
package main
import (
"flag"
"fmt"
"os"
gengo "code.cestus.io/blaze/cmd/protoc-gen-blaze/internal_gengo"
"github.com/go-logr/logr"
"github.com/magicmoose/zapr"
"go.uber.org/zap"
"google.golang.org/protobuf/compiler/protogen"
)
var (
// Version is the version of the application
Version string = "v0.6.0"
// BuildTime is the time the application was build
BuildTime string
)
// NewZapDevelopmentConfig is a development logger config
func NewZapDevelopmentConfig() zap.Config {
return zap.Config{
Level: zap.NewAtomicLevelAt(-3),
Development: false,
Encoding: "json",
EncoderConfig: zap.NewProductionEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
}
func main() {
versionFlag := flag.Bool("version", false, "print version and exit")
flag.Parse()
if *versionFlag {
fmt.Println(Version)
os.Exit(0)
}
var (
log logr.Logger
flags flag.FlagSet
)
zapLog, err := NewZapDevelopmentConfig().Build()
if err != nil {
panic(fmt.Sprintf("Cannot init logger (%v)?", err))
}
log = zapr.NewLogger(zapLog).WithValues("version", Version).WithName("test")
blaze := gengo.NewGenerator(log, Version)
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = gengo.SupportedFeatures
for _, f := range gen.Files {
if f.Generate {
blaze.GenerateFile(gen, f)
blaze.GenerateSampleFile(gen, f)
}
}
return nil
})
//g := newGenerator(log)
//generator.Generate(g)
}