1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/plugins/transport/grpc/handler.go
Asim Aslam 62801c3d68 update
2021-10-13 13:31:23 +01:00

44 lines
834 B
Go

package grpc
import (
"runtime/debug"
"go-micro.dev/v4/errors"
"go-micro.dev/v4/logger"
"go-micro.dev/v4/transport"
pb "github.com/asim/go-micro/plugins/transport/grpc/v4/proto"
"google.golang.org/grpc/peer"
)
// microTransport satisfies the pb.TransportServer inteface
type microTransport struct {
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
}