-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.go
More file actions
41 lines (34 loc) · 1020 Bytes
/
handler.go
File metadata and controls
41 lines (34 loc) · 1020 Bytes
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
package main
import (
"context"
"fmt"
"github.com/protobuf-orm/protobuf-orm/graph"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/pluginpb"
)
type Handler struct {
Store StoreOpts
Query QueryOpts
}
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)
}
if err := h.Store.Run(ctx, p, g); err != nil {
return fmt.Errorf("run store app: %w", err)
}
if err := h.Query.Run(ctx, p, g); err != nil {
return fmt.Errorf("run query app: %w", err)
}
return nil
}