mirror of
https://github.com/siderolabs/talos.git
synced 2025-09-11 17:01:20 +02:00
That's the recommended syntax: https://golangci-lint.run/usage/false-positives/ Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
33 lines
751 B
Go
33 lines
751 B
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package client
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"google.golang.org/grpc/peer"
|
|
)
|
|
|
|
// RemotePeer parses remote peer address from grpc stream context.
|
|
func RemotePeer(ctx context.Context) (peerHost string) {
|
|
peerHost = "unknown"
|
|
|
|
remote, ok := peer.FromContext(ctx)
|
|
if ok {
|
|
peerHost = AddrFromPeer(remote)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// AddrFromPeer extracts peer address from grpc Peer.
|
|
func AddrFromPeer(remote *peer.Peer) (peerHost string) {
|
|
peerHost = remote.Addr.String()
|
|
peerHost, _, _ = net.SplitHostPort(peerHost) //nolint:errcheck
|
|
|
|
return peerHost
|
|
}
|