From 9fedfb83b0be81672ead678c5df880b9f90ff793 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Mon, 12 Jun 2023 00:07:12 +0200 Subject: [PATCH] refactor!: options approach for experiments --- bot.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bot.go b/bot.go index f100ecf..618a047 100644 --- a/bot.go +++ b/bot.go @@ -30,21 +30,24 @@ type CwtchBot struct { experiments []string } -func NewCwtchBot(userdir string, peername string) *CwtchBot { - cb := new(CwtchBot) - cb.dir = userdir - cb.peername = peername - cb.engineHooks = connections.DefaultEngineHooks{} - cb.experiments = nil - return cb +// CwtchBotOption modifies a new CwtchBot. +type CwtchBotOption func(c *CwtchBot) + +// WithExperiments specifies the experiments option of a CwtchBot. +func WithExperiments(experiments []string) CwtchBotOption { + return func(c *CwtchBot) { + c.experiments = experiments + } } -func NewCwtchBotWithExperiments(userdir string, peername string, experiments []string) *CwtchBot { +func NewCwtchBot(userdir, peername string, opts ...CwtchBotOption) *CwtchBot { cb := new(CwtchBot) cb.dir = userdir cb.peername = peername cb.engineHooks = connections.DefaultEngineHooks{} - cb.experiments = experiments + for _, optFunc := range opts { + optFunc(cb) + } return cb }