Further consolidate the libraries
This commit is contained in:
58
service/grpc/grpc.go
Normal file
58
service/grpc/grpc.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro"
|
||||
broker "github.com/micro/go-micro/broker"
|
||||
client "github.com/micro/go-micro/client"
|
||||
server "github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
// 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...)
|
||||
}
|
Reference in New Issue
Block a user