| 1 |
package main |
| 2 |
|
| 3 |
type Pooler interface { |
| 4 |
Get() string |
| 5 |
} |
| 6 |
|
| 7 |
type baseClient struct { |
| 8 |
connPool Pooler |
| 9 |
} |
| 10 |
|
| 11 |
type connPool struct { |
| 12 |
name string |
| 13 |
} |
| 14 |
|
| 15 |
func (c *connPool) Get() string { return c.name } |
| 16 |
|
| 17 |
func newBaseClient(i int, p Pooler) *baseClient { |
| 18 |
return &baseClient{connPool: p} |
| 19 |
} |
| 20 |
|
| 21 |
func newConnPool() *connPool { return &connPool{name: "connPool"} } |
| 22 |
|
| 23 |
func main() { |
| 24 |
b := newBaseClient(0, newConnPool()) |
| 25 |
println(b.connPool.(*connPool).name) |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|