/
info_router.pb.go
78 lines (65 loc) · 2.02 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
// Code generated by protoc-gen-router. DO NOT EDIT.
package hail
import (
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.HailInfoServer that allows routing named requests to specific traits.HailInfoClient
type InfoRouter struct {
traits.UnimplementedHailInfoServer
router.Router
}
// compile time check that we implement the interface we need
var _ traits.HailInfoServer = (*InfoRouter)(nil)
func NewInfoRouter(opts ...router.Option) *InfoRouter {
return &InfoRouter{
Router: router.NewRouter(opts...),
}
}
// WithHailInfoClientFactory instructs the router to create a new
// client the first time Get is called for that name.
func WithHailInfoClientFactory(f func(name string) (traits.HailInfoClient, error)) router.Option {
return router.WithFactory(func(name string) (any, error) {
return f(name)
})
}
func (r *InfoRouter) Register(server *grpc.Server) {
traits.RegisterHailInfoServer(server, r)
}
// Add extends Router.Add to panic if client is not of type traits.HailInfoClient.
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.HailInfoClient", client))
}
return r.Router.Add(name, client)
}
func (r *InfoRouter) HoldsType(client any) bool {
_, ok := client.(traits.HailInfoClient)
return ok
}
func (r *InfoRouter) AddHailInfoClient(name string, client traits.HailInfoClient) traits.HailInfoClient {
res := r.Add(name, client)
if res == nil {
return nil
}
return res.(traits.HailInfoClient)
}
func (r *InfoRouter) RemoveHailInfoClient(name string) traits.HailInfoClient {
res := r.Remove(name)
if res == nil {
return nil
}
return res.(traits.HailInfoClient)
}
func (r *InfoRouter) GetHailInfoClient(name string) (traits.HailInfoClient, error) {
res, err := r.Get(name)
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}
return res.(traits.HailInfoClient), nil
}