diff options
author | 2024-08-26 18:05:54 +0200 | |
---|---|---|
committer | 2024-08-26 18:05:54 +0200 | |
commit | 28d57d1f13ee61a6ff83ce4beaf238139d20bbac (patch) | |
tree | 7946abb44b21f9e2f4267146711760a911072c9b /vendor/google.golang.org/grpc/peer/peer.go | |
parent | [chore]: Bump github.com/prometheus/client_golang from 1.20.0 to 1.20.2 (#3239) (diff) | |
download | gotosocial-28d57d1f13ee61a6ff83ce4beaf238139d20bbac.tar.xz |
[chore] Bump all otel deps (#3241)
Diffstat (limited to 'vendor/google.golang.org/grpc/peer/peer.go')
-rw-r--r-- | vendor/google.golang.org/grpc/peer/peer.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/google.golang.org/grpc/peer/peer.go b/vendor/google.golang.org/grpc/peer/peer.go index a821ff9b2..499a49c8c 100644 --- a/vendor/google.golang.org/grpc/peer/peer.go +++ b/vendor/google.golang.org/grpc/peer/peer.go @@ -22,7 +22,9 @@ package peer import ( "context" + "fmt" "net" + "strings" "google.golang.org/grpc/credentials" ) @@ -39,6 +41,34 @@ type Peer struct { AuthInfo credentials.AuthInfo } +// String ensures the Peer types implements the Stringer interface in order to +// allow to print a context with a peerKey value effectively. +func (p *Peer) String() string { + if p == nil { + return "Peer<nil>" + } + sb := &strings.Builder{} + sb.WriteString("Peer{") + if p.Addr != nil { + fmt.Fprintf(sb, "Addr: '%s', ", p.Addr.String()) + } else { + fmt.Fprintf(sb, "Addr: <nil>, ") + } + if p.LocalAddr != nil { + fmt.Fprintf(sb, "LocalAddr: '%s', ", p.LocalAddr.String()) + } else { + fmt.Fprintf(sb, "LocalAddr: <nil>, ") + } + if p.AuthInfo != nil { + fmt.Fprintf(sb, "AuthInfo: '%s'", p.AuthInfo.AuthType()) + } else { + fmt.Fprintf(sb, "AuthInfo: <nil>") + } + sb.WriteString("}") + + return sb.String() +} + type peerKey struct{} // NewContext creates a new context with peer information attached. |