2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-12-14 15:24:22 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKeyRemoteAddr struct{}
|
|
|
|
|
|
|
|
func ContextWithRemoteAddr(ctx context.Context, addr net.Addr) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyRemoteAddr{}, addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func RemoteAddrFromContext(ctx context.Context) (net.Addr, bool) {
|
|
|
|
v := ctx.Value(contextKeyRemoteAddr{})
|
|
|
|
if v == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
return v.(net.Addr), true
|
|
|
|
}
|