micro/service/grpc/grpc.go

59 lines
1.3 KiB
Go
Raw Normal View History

2019-06-03 20:44:43 +03:00
package grpc
import (
"time"
"github.com/micro/go-micro"
broker "github.com/micro/go-micro/broker"
2019-06-05 08:39:56 +03:00
client "github.com/micro/go-micro/client/grpc"
server "github.com/micro/go-micro/server/grpc"
2019-06-03 20:44:43 +03: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...)
}