github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/infra/errcode/options.go (about) 1 package errcode 2 3 func (p *Registry) applyOptions(options ...Option) { 4 for _, o := range options { 5 if o.applyRegistry != nil { 6 o.applyRegistry(p) 7 } 8 } 9 } 10 11 // An Option customizes the behavior of Registry. 12 type Option struct { 13 applyRegistry func(*Registry) 14 } 15 16 // WithReserved returns an option to make a Registry to reserve some codes. 17 // Calling Register with a reserved code causes a panic. 18 // Reserved code can be registered by calling RegisterReserved. 19 func WithReserved(fn func(code int32) bool) Option { 20 return Option{ 21 applyRegistry: func(r *Registry) { 22 r.reserve = fn 23 }, 24 } 25 }