示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package proxy import ( "net" ) type direct struct{} // Direct is a direct proxy: one that makes network connections directly. var Direct = direct{} func (direct) Dial(network, addr string) (net.Conn, error) { return net.Dial(network, addr) } |
上面是 golang.org/x/net/proxy/direct.go 里面的代码
- 我们显然是可以在proxy包外访问到Direct变量的
- 我们显然是无法在proxy包外new 一个 direct 结构变量的
- 由于2,而且我们无法改变Direct的变量类型,所以,我们做不到给Direct进行重新赋值