Vasiliy Tolstov
06136312bb
* regen files with never protoc * rewrite import path Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
45 lines
915 B
Go
45 lines
915 B
Go
package grpc
|
|
|
|
import (
|
|
"runtime/debug"
|
|
|
|
"github.com/unistack-org/micro/v3/errors"
|
|
"github.com/unistack-org/micro/v3/logger"
|
|
"github.com/unistack-org/micro/v3/transport"
|
|
pb "github.com/unistack-org/micro/v3/transport/grpc/proto"
|
|
"google.golang.org/grpc/peer"
|
|
)
|
|
|
|
// microTransport satisfies the pb.TransportServer inteface
|
|
type microTransport struct {
|
|
pb.UnimplementedTransportServer
|
|
addr string
|
|
fn func(transport.Socket)
|
|
}
|
|
|
|
func (m *microTransport) Stream(ts pb.Transport_StreamServer) (err error) {
|
|
|
|
sock := &grpcTransportSocket{
|
|
stream: ts,
|
|
local: m.addr,
|
|
}
|
|
|
|
p, ok := peer.FromContext(ts.Context())
|
|
if ok {
|
|
sock.remote = p.Addr.String()
|
|
}
|
|
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
logger.Error(r, string(debug.Stack()))
|
|
sock.Close()
|
|
err = errors.InternalServerError("go.micro.transport", "panic recovered: %v", r)
|
|
}
|
|
}()
|
|
|
|
// execute socket func
|
|
m.fn(sock)
|
|
|
|
return err
|
|
}
|