github.com/songzhibin97/gkit@v1.2.13/egroup/option.go (about)

     1  package egroup
     2  
     3  import (
     4  	"os"
     5  	"time"
     6  
     7  	"github.com/songzhibin97/gkit/options"
     8  )
     9  
    10  // config
    11  type config struct {
    12  	// startTimeout: 启动超时时间
    13  	// <=0 不启动超时时间,注意要在shutdown处理关闭通知
    14  	startTimeout time.Duration
    15  
    16  	// stopTimeout: 关闭超时时间
    17  	// <=0 不启动超时时间
    18  	stopTimeout time.Duration
    19  
    20  	// signals: 信号集
    21  	signals []os.Signal
    22  
    23  	// handler: 捕捉信号后处理函数
    24  	handler func(*LifeAdmin, os.Signal)
    25  }
    26  
    27  // SetStartTimeout 设置启动超时时间
    28  func SetStartTimeout(d time.Duration) options.Option {
    29  	return func(c interface{}) { c.(*config).startTimeout = d }
    30  }
    31  
    32  // SetStopTimeout 设置停止超时时间
    33  func SetStopTimeout(d time.Duration) options.Option {
    34  	return func(c interface{}) { c.(*config).stopTimeout = d }
    35  }
    36  
    37  // SetSignal 设置信号集合,和处理信号的函数
    38  func SetSignal(handler func(*LifeAdmin, os.Signal), signals ...os.Signal) options.Option {
    39  	return func(c interface{}) {
    40  		conf := c.(*config)
    41  		conf.handler = handler
    42  		conf.signals = signals
    43  	}
    44  }