From 3bc662796f5005f7e067452d21f04be156a69bdd Mon Sep 17 00:00:00 2001 From: Ash Keel Date: Sun, 4 Dec 2022 18:34:59 +0100 Subject: [PATCH] fix: fix misuses of wrapped values --- http/server.go | 11 ++++++++--- twitch/bot.go | 2 +- twitch/bot.timer.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/http/server.go b/http/server.go index 72221b2..7a4b0d5 100644 --- a/http/server.go +++ b/http/server.go @@ -14,7 +14,6 @@ import ( "go.uber.org/zap" "github.com/strimertul/strimertul/database" - "github.com/strimertul/strimertul/utils" ) var json = jsoniter.ConfigFastest @@ -40,8 +39,12 @@ func NewServer(db *database.LocalDBClient, logger *zap.Logger) (*Server, error) Config: sync.NewRWSync(ServerConfig{}), } - err := utils.LoadJSONToWrapped[ServerConfig](ServerConfigKey, server.Config) + var config ServerConfig + err := db.GetJSON(ServerConfigKey, &config) if err != nil { + if err != database.ErrEmptyKey { + logger.Warn("HTTP config is corrupted or could not be read", zap.Error(err)) + } // Initialize with default config server.Config.Set(ServerConfig{ Bind: "localhost:4337", @@ -49,10 +52,12 @@ func NewServer(db *database.LocalDBClient, logger *zap.Logger) (*Server, error) KVPassword: "", }) // Save - err = db.PutJSON(ServerConfigKey, server.Config) + err = db.PutJSON(ServerConfigKey, server.Config.Get()) if err != nil { return nil, err } + } else { + server.Config.Set(config) } // Set hub diff --git a/twitch/bot.go b/twitch/bot.go index 48f8ba0..7e61514 100644 --- a/twitch/bot.go +++ b/twitch/bot.go @@ -147,7 +147,7 @@ func newBot(api *Client, config BotConfig) *Bot { history = history[len(history)-bot.Config.ChatHistory+1:] } bot.chatHistory.Set(append(history, message)) - err = bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory) + err = bot.api.db.PutJSON(ChatHistoryKey, bot.chatHistory.Get()) if err != nil { bot.logger.Warn("could not save message to chat history", zap.Error(err)) } diff --git a/twitch/bot.timer.go b/twitch/bot.timer.go index b9fec1a..00a2524 100644 --- a/twitch/bot.timer.go +++ b/twitch/bot.timer.go @@ -92,7 +92,7 @@ func (m *BotTimerModule) runTimers() { timeUntilNextTick := nextTick.Sub(currentTime) time.Sleep(timeUntilNextTick) - err := m.bot.api.db.PutJSON(ChatActivityKey, m.messages) + err := m.bot.api.db.PutJSON(ChatActivityKey, m.messages.Get()) if err != nil { m.bot.logger.Warn("error saving chat activity", zap.Error(err)) }