2019-06-03 18:44:43 +01:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/micro/go-micro"
|
|
|
|
broker "github.com/micro/go-micro/broker"
|
2019-06-05 06:39:56 +01:00
|
|
|
client "github.com/micro/go-micro/client/grpc"
|
|
|
|
server "github.com/micro/go-micro/server/grpc"
|
2019-06-03 18:44:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
// our grpc broker
|
|
|
|
b := broker.NewBroker()
|
|
|
|
|
|
|
|
// create options with priority for our opts
|
|
|
|
options := []micro.Option{
|
|
|
|
micro.Client(c),
|
|
|
|
micro.Server(s),
|
|
|
|
micro.Broker(b),
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
// our grpc broker
|
|
|
|
b := broker.NewBroker()
|
|
|
|
|
|
|
|
// create options with priority for our opts
|
|
|
|
options := []micro.Option{
|
|
|
|
micro.Client(c),
|
|
|
|
micro.Server(s),
|
|
|
|
micro.Broker(b),
|
|
|
|
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...)
|
|
|
|
}
|