refactor!: options approach for experiments
This commit is contained in:
parent
804e6e8d9b
commit
9fedfb83b0
21
bot.go
21
bot.go
|
@ -30,21 +30,24 @@ type CwtchBot struct {
|
||||||
experiments []string
|
experiments []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCwtchBot(userdir string, peername string) *CwtchBot {
|
// CwtchBotOption modifies a new CwtchBot.
|
||||||
cb := new(CwtchBot)
|
type CwtchBotOption func(c *CwtchBot)
|
||||||
cb.dir = userdir
|
|
||||||
cb.peername = peername
|
// WithExperiments specifies the experiments option of a CwtchBot.
|
||||||
cb.engineHooks = connections.DefaultEngineHooks{}
|
func WithExperiments(experiments []string) CwtchBotOption {
|
||||||
cb.experiments = nil
|
return func(c *CwtchBot) {
|
||||||
return cb
|
c.experiments = experiments
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCwtchBotWithExperiments(userdir string, peername string, experiments []string) *CwtchBot {
|
func NewCwtchBot(userdir, peername string, opts ...CwtchBotOption) *CwtchBot {
|
||||||
cb := new(CwtchBot)
|
cb := new(CwtchBot)
|
||||||
cb.dir = userdir
|
cb.dir = userdir
|
||||||
cb.peername = peername
|
cb.peername = peername
|
||||||
cb.engineHooks = connections.DefaultEngineHooks{}
|
cb.engineHooks = connections.DefaultEngineHooks{}
|
||||||
cb.experiments = experiments
|
for _, optFunc := range opts {
|
||||||
|
optFunc(cb)
|
||||||
|
}
|
||||||
return cb
|
return cb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue