summaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/grpc/peer/peer.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/grpc/peer/peer.go')
-rw-r--r--vendor/google.golang.org/grpc/peer/peer.go30
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.