var defaultMaxSize = 10 var defaultMinSize = 0 var defaultIdleSize = 1
// go语言中通常以如下方式来构造复杂参数对象,非传统建造者模式 // 说明:资源池配置,name为必传参数,其他为可选参数 type ResourcePoolConfig struct { // 必传参数 name string // 可选参数 maxSize int minSize int idleSize int }
type ResourcePoolConfigOptions struct { maxSize int minSize int idleSize int }
type ResourcePoolConfigOptionsFun func(option *ResourcePoolConfigOptions)
funcNewResourcePoolConfig(name string, opts ...ResourcePoolConfigOptionsFun)ResourcePoolConfig { if name == "" { panic("name can not be nil") }