| 1 |
package dnsctx |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"net/netip" |
| 6 |
) |
| 7 |
|
| 8 |
// Addr returns a netip.Addr from the context. |
| 9 |
func Addr(ctx context.Context, key string) netip.Addr { |
| 10 |
x := Value(ctx, key) |
| 11 |
if x == nil { |
| 12 |
return netip.Addr{} |
| 13 |
} |
| 14 |
if a, ok := x.(netip.Addr); ok { |
| 15 |
return a |
| 16 |
} |
| 17 |
return netip.Addr{} |
| 18 |
} |
| 19 |
|
| 20 |
// String returns a string from the context under key. |
| 21 |
func String(ctx context.Context, key string) string { |
| 22 |
x := Value(ctx, key) |
| 23 |
if x == nil { |
| 24 |
return "" |
| 25 |
} |
| 26 |
if s, ok := x.(string); ok { |
| 27 |
return s |
| 28 |
} |
| 29 |
return "" |
| 30 |
} |