decred.org/dcrwallet/v3@v3.1.0/internal/rpc/jsonrpc/context.go (about) 1 // Copyright (c) 2017 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package jsonrpc 6 7 import "context" 8 9 type contextKey string 10 11 func withRemoteAddr(parent context.Context, remoteAddr string) context.Context { 12 return context.WithValue(parent, contextKey("remote-addr"), remoteAddr) 13 } 14 15 func remoteAddr(ctx context.Context) string { 16 v := ctx.Value(contextKey("remote-addr")) 17 if v == nil { 18 return "<unknown>" 19 } 20 return v.(string) 21 }