github.com/searKing/golang/go@v1.2.117/net/tcp/context.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tcp 6 7 var ( 8 // ServerContextKey is a context key. It can be used in TCP 9 // handlers with context.WithValue to access the server that 10 // started the handler. The associated value will be of 11 // type *Server. 12 ServerContextKey = &contextKey{"tcp-server"} 13 // ClientContextKey is a context key. It can be used in TCP 14 // handlers with context.WithValue to access the client that 15 // started the handler. The associated value will be of 16 // type *Client. 17 ClientContextKey = &contextKey{"tcp-client"} 18 19 // LocalAddrContextKey is a context key. It can be used in 20 // TCP handlers with context.WithValue to access the local 21 // address the connection arrived on. 22 // The associated value will be of type net.Addr. 23 LocalAddrContextKey = &contextKey{"local-addr"} 24 ) 25 26 type contextKey struct { 27 name string 28 } 29 30 func (k *contextKey) String() string { return "net/http context value " + k.name }