github.com/searKing/golang/go@v1.2.117/net/mux/context_key.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 mux 6 7 var ( 8 // ServerContextKey is a context key. It can be used in cmux 9 // handlers with context.WithValue to access the server that 10 // started the handler. The associated value will be of 11 // type CMuxer. 12 ServerContextKey = &contextKey{"cmux-server"} 13 14 // LocalAddrContextKey is a context key. It can be used in 15 // cmux handlers with context.WithValue to access the local 16 // address the connection arrived on. 17 // The associated value will be of type net.Addr. 18 LocalAddrContextKey = &contextKey{"local-addr"} 19 ) 20 21 // contextKey is a value for use with context.WithValue. It's used as 22 // a pointer so it fits in an interface{} without allocation. 23 type contextKey struct { 24 name string 25 } 26 27 func (k *contextKey) String() string { return "net/mux context value " + k.name }