1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

further transport rework

This commit is contained in:
Asim
2015-05-21 19:24:57 +01:00
parent b555109fbb
commit 9d514f0e60
11 changed files with 209 additions and 137 deletions

View File

@ -14,11 +14,11 @@ import (
)
type RpcServer struct {
mtx sync.RWMutex
address string
transport transport.Transport
rpc *rpc.Server
exit chan chan error
mtx sync.RWMutex
address string
opts options
rpc *rpc.Server
exit chan chan error
}
var (
@ -96,7 +96,7 @@ func (s *RpcServer) Register(r Receiver) error {
func (s *RpcServer) Start() error {
registerHealthChecker(http.DefaultServeMux)
ts, err := s.transport.NewServer(Name, s.address)
ts, err := s.opts.transport.NewServer(s.address)
if err != nil {
return err
}
@ -123,11 +123,21 @@ func (s *RpcServer) Stop() error {
return <-ch
}
func NewRpcServer(address string) *RpcServer {
func NewRpcServer(address string, opt ...Options) *RpcServer {
var opts options
for _, o := range opt {
o(&opts)
}
if opts.transport == nil {
opts.transport = transport.DefaultTransport
}
return &RpcServer{
address: address,
transport: transport.DefaultTransport,
rpc: rpc.NewServer(),
exit: make(chan chan error),
opts: opts,
address: address,
rpc: rpc.NewServer(),
exit: make(chan chan error),
}
}