-
Notifications
You must be signed in to change notification settings - Fork 3
/
info_router.pb.go
88 lines (73 loc) · 2.32 KB
/
info_router.pb.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Code generated by protoc-gen-router. DO NOT EDIT.
package count
import (
context "context"
fmt "fmt"
traits "github.com/smart-core-os/sc-api/go/traits"
router "github.com/smart-core-os/sc-golang/pkg/router"
grpc "google.golang.org/grpc"
)
// InfoRouter is a traits.CountInfoServer that allows routing named requests to specific traits.CountInfoClient
type InfoRouter struct {
traits.UnimplementedCountInfoServer
router.Router
}
// compile time check that we implement the interface we need
var _ traits.CountInfoServer = (*InfoRouter)(nil)
func NewInfoRouter(opts ...router.Option) *InfoRouter {
return &InfoRouter{
Router: router.NewRouter(opts...),
}
}
// WithCountInfoClientFactory instructs the router to create a new
// client the first time Get is called for that name.
func WithCountInfoClientFactory(f func(name string) (traits.CountInfoClient, error)) router.Option {
return router.WithFactory(func(name string) (any, error) {
return f(name)
})
}
func (r *InfoRouter) Register(server *grpc.Server) {
traits.RegisterCountInfoServer(server, r)
}
// Add extends Router.Add to panic if client is not of type traits.CountInfoClient.
func (r *InfoRouter) Add(name string, client any) any {
if !r.HoldsType(client) {
panic(fmt.Sprintf("not correct type: client of type %T is not a traits.CountInfoClient", client))
}
return r.Router.Add(name, client)
}
func (r *InfoRouter) HoldsType(client any) bool {
_, ok := client.(traits.CountInfoClient)
return ok
}
func (r *InfoRouter) AddCountInfoClient(name string, client traits.CountInfoClient) traits.CountInfoClient {
res := r.Add(name, client)
if res == nil {
return nil
}
return res.(traits.CountInfoClient)
}
func (r *InfoRouter) RemoveCountInfoClient(name string) traits.CountInfoClient {
res := r.Remove(name)
if res == nil {
return nil
}
return res.(traits.CountInfoClient)
}
func (r *InfoRouter) GetCountInfoClient(name string) (traits.CountInfoClient, error) {
res, err := r.Get(name)
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(traits.CountInfoClient), nil
}
func (r *InfoRouter) DescribeCount(ctx context.Context, request *traits.DescribeCountRequest) (*traits.CountSupport, error) {
child, err := r.GetCountInfoClient(request.Name)
if err != nil {
return nil, err
}
return child.DescribeCount(ctx, request)
}