micro/transport/grpc/handler.go
Vasiliy Tolstov 117f56ebf7
prune util/log and user logger (#1237)
* prune util/log and user logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* plaintext logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>

* add newline

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-23 13:45:20 +00:00

44 lines
867 B
Go

package grpc
import (
"runtime/debug"
"github.com/micro/go-micro/v2/errors"
log "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/transport"
pb "github.com/micro/go-micro/v2/transport/grpc/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 {
log.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
}