-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
50 lines (41 loc) · 1.17 KB
/
handler.go
File metadata and controls
50 lines (41 loc) · 1.17 KB
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 (
"context"
"fmt"
"text/template"
"github.com/protobuf-orm/protobuf-orm/graph"
"github.com/protobuf-orm/protoc-gen-orm-service/app"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)
type Handler struct {
Namer string
}
func (h *Handler) Run(p *protogen.Plugin) error {
p.SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO2
p.SupportedEditionsMaximum = descriptorpb.Edition_EDITION_MAX
p.SupportedFeatures = uint64(0 |
pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL |
pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS,
)
ctx := context.Background()
// TODO: set logger
g := graph.NewGraph()
if err := graph.ParseFiles(ctx, g, p.Files); err != nil {
return fmt.Errorf("parse entities: %w", err)
}
opts := []app.Option{}
if h.Namer != "" {
v, err := template.New("namer").Parse(h.Namer)
if err != nil {
return fmt.Errorf("opt.namer: %w", err)
}
opts = append(opts, app.WithNamer(v))
}
app, err := app.New(opts...)
if err != nil {
return fmt.Errorf("initialize plugin: %w", err)
}
return app.Run(ctx, p, g)
}