package service type options struct { capacity int32 onInit OnInit onStop OnStop onNotifyStop OnNotifyStop canStop CanStop } type OnInit func(IService) bool type OnStop func(IService) type OnNotifyStop func(IService) type CanStop func(IService) bool func defaultOnInit(_ IService) bool { return true } func defaultOnStop(_ IService) { } func defaultOnNotifyStop(_ IService) { } type Option func(*options) func SetCapacity(capacity int32) Option { return func(op *options) { if capacity <= 0 { capacity = 256 } op.capacity = capacity } } func SetOnInit(onInit OnInit) Option { return func(op *options) { op.onInit = onInit } } func SetOnStop(onStop OnStop) Option { return func(op *options) { op.onStop = onStop } } func SetOnNotifyStop(onNotifyStop OnNotifyStop) Option { return func(op *options) { op.onNotifyStop = onNotifyStop } } func SetCanStop(canStop CanStop) Option { return func(op *options) { op.canStop = canStop } }