add missing transport folder

This commit is contained in:
Adphi 2021-09-30 12:00:22 +02:00
parent 1eea54f18a
commit 89ebbee8dc
5 changed files with 83 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
.idea
.bin
transport

View File

@ -220,7 +220,7 @@ func (s *service) run() error {
logrus.Warnf("received %v", sig)
return s.Close()
case err := <-errs:
if err != nil {
if err != nil && !ignoreMuxError(err){
logrus.Error(err)
return err
}

15
transport/grpc/grpc.go Normal file
View File

@ -0,0 +1,15 @@
package grpc
import (
"google.golang.org/grpc"
"go.linka.cloud/grpc/transport"
)
var (
_ transport.Transport = &grpc.Server{}
)
func New() transport.Transport {
return grpc.NewServer()
}

View File

@ -0,0 +1,53 @@
package inproc
import (
"errors"
"net"
"sync"
"github.com/fullstorydev/grpchan/inprocgrpc"
"go.linka.cloud/grpc/transport"
)
var (
_ transport.Transport = &InProc{}
)
func New() transport.Transport {
return &InProc{stop: make(chan struct{})}
}
type InProc struct {
inprocgrpc.Channel
stop chan struct{}
running bool
mu sync.RWMutex
}
func (i *InProc) Serve(_ net.Listener) error {
i.mu.RLock()
running := i.running
i.mu.RUnlock()
if running {
return errors.New("already running")
}
i.mu.Lock()
i.running = true
i.mu.Unlock()
<-i.stop
return nil
}
func (i *InProc) Stop() {
i.mu.RLock()
running := i.running
i.mu.RUnlock()
if running {
i.stop <- struct{}{}
}
}
func (i *InProc) GracefulStop() {
i.Stop()
}

14
transport/transport.go Normal file
View File

@ -0,0 +1,14 @@
package transport
import (
"net"
"google.golang.org/grpc"
)
type Transport interface {
grpc.ServiceRegistrar
Serve(lis net.Listener) error
Stop()
GracefulStop()
}