1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-28 21:09:04 +02:00
kratos/selector/peer.go
longxboy 123fc1e6c8
feat: add peer for selector (#2088)
* add peer for selector
2022-06-07 22:38:21 +08:00

26 lines
604 B
Go

package selector
import (
"context"
)
type peerKey struct{}
// Peer contains the information of the peer for an RPC, such as the address
// and authentication information.
type Peer struct {
// node is the peer node.
Node Node
}
// NewPeerContext creates a new context with peer information attached.
func NewPeerContext(ctx context.Context, p *Peer) context.Context {
return context.WithValue(ctx, peerKey{}, p)
}
// FromPeerContext returns the peer information in ctx if it exists.
func FromPeerContext(ctx context.Context) (p *Peer, ok bool) {
p, ok = ctx.Value(peerKey{}).(*Peer)
return
}