-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-grpc.go
52 lines (41 loc) · 1.16 KB
/
go-grpc.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
package grpc
import (
"time"
"github.com/micro/go-micro"
client "github.com/micro/go-plugins/client/grpc"
server "github.com/micro/go-plugins/server/grpc"
)
// NewService returns a grpc service compatible with go-micro.Service
func NewService(opts ...micro.Option) micro.Service {
// our grpc client
c := client.NewClient()
// our grpc server
s := server.NewServer()
// create options with priority for our opts
options := []micro.Option{
micro.Client(c),
micro.Server(s),
}
// append passed in opts
options = append(options, opts...)
// generate and return a service
return micro.NewService(options...)
}
// NewFunction returns a grpc service compatible with go-micro.Function
func NewFunction(opts ...micro.Option) micro.Function {
// our grpc client
c := client.NewClient()
// our grpc server
s := server.NewServer()
// create options with priority for our opts
options := []micro.Option{
micro.Client(c),
micro.Server(s),
micro.RegisterTTL(time.Minute),
micro.RegisterInterval(time.Second * 30),
}
// append passed in opts
options = append(options, opts...)
// generate and return a function
return micro.NewFunction(options...)
}