1 Star 0 Fork 0

larrypu / go-plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
handler.go 714 Bytes
一键复制 编辑 原始数据 按行查看 历史
Asim Aslam 提交于 2018-11-14 20:11 . add local/remote ip methods
package grpc
import (
"runtime/debug"
"github.com/micro/go-log"
"github.com/micro/go-micro/transport"
pb "github.com/micro/go-plugins/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) 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.Log(r, string(debug.Stack()))
sock.Close()
}
}()
// execute socket func
m.fn(sock)
return nil
}
1
https://gitee.com/larrypu/go-plugins.git
git@gitee.com:larrypu/go-plugins.git
larrypu
go-plugins
go-plugins
v0.21.1

搜索帮助