mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-24 03:46:24 +00:00
add missing transport folder
This commit is contained in:
parent
1eea54f18a
commit
89ebbee8dc
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
.idea
|
||||
.bin
|
||||
transport
|
||||
|
@ -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
15
transport/grpc/grpc.go
Normal 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()
|
||||
}
|
53
transport/inproc/inproc.go
Normal file
53
transport/inproc/inproc.go
Normal 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
14
transport/transport.go
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user