From 39ec8f2764e41a2882ee3016aa3f726e33d7a6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Sun, 24 Mar 2024 16:54:33 +0100 Subject: [PATCH] Make config fields public --- config.go | 38 +++++++++++++++++++------------------- main.go | 8 ++++---- sender_worker.go | 6 +++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/config.go b/config.go index 15ae3aa..557d858 100644 --- a/config.go +++ b/config.go @@ -13,14 +13,14 @@ import ( ) type AppConfig struct { - satelAddr string - chatIds []int64 - allowedTypes []satel.ChangeType - allowedIndexes []int - poolInterval time.Duration - armCallbackUrls []string - disarmCallbackUrls []string - alarmCallbackUrls []string + SatelAddr string + ChatIds []int64 + AllowedTypes []satel.ChangeType + AllowedIndexes []int + PoolInterval time.Duration + ArmCallbackUrls []string + DisarmCallbackUrls []string + AlarmCallbackUrls []string } func getCmdLineParams(config *AppConfig, logger *log.Logger) { @@ -71,27 +71,27 @@ func getCmdLineParams(config *AppConfig, logger *log.Logger) { satelAddr := fmt.Sprintf("%s:%s", *satelApiAddr, *satelApiPort) - config.satelAddr = satelAddr - config.chatIds = chatIds - config.allowedTypes = allowedTypes - config.allowedIndexes = allowedIndexes - config.poolInterval = *satelPoolInterval + config.SatelAddr = satelAddr + config.ChatIds = chatIds + config.AllowedTypes = allowedTypes + config.AllowedIndexes = allowedIndexes + config.PoolInterval = *satelPoolInterval } func MakeConfig(logger *log.Logger) AppConfig { config := AppConfig{} - config.armCallbackUrls = []string{} - config.disarmCallbackUrls = []string{} - config.alarmCallbackUrls = []string{} + config.ArmCallbackUrls = []string{} + config.DisarmCallbackUrls = []string{} + config.AlarmCallbackUrls = []string{} if len(os.Getenv("NOTIFY_URL_ARM")) != 0 { - config.armCallbackUrls = append(config.armCallbackUrls, os.Getenv("NOTIFY_URL_ARM")) + config.ArmCallbackUrls = append(config.ArmCallbackUrls, os.Getenv("NOTIFY_URL_ARM")) } if len(os.Getenv("NOTIFY_URL_DISARM")) != 0 { - config.disarmCallbackUrls = append(config.disarmCallbackUrls, os.Getenv("NOTIFY_URL_DISARM")) + config.DisarmCallbackUrls = append(config.DisarmCallbackUrls, os.Getenv("NOTIFY_URL_DISARM")) } if len(os.Getenv("ALARM_URL_ARM")) != 0 { - config.alarmCallbackUrls = append(config.alarmCallbackUrls, os.Getenv("ALARM_URL_ARM")) + config.AlarmCallbackUrls = append(config.AlarmCallbackUrls, os.Getenv("ALARM_URL_ARM")) } getCmdLineParams(&config, logger) diff --git a/main.go b/main.go index 4e467ba..9003652 100644 --- a/main.go +++ b/main.go @@ -58,8 +58,8 @@ func main() { stopRequested.Store(false) config := MakeConfig(logger) - s := makeSatel(config.satelAddr, config.poolInterval) - logger.Printf("Connected to Satel: %s", config.satelAddr) + s := makeSatel(config.SatelAddr, config.PoolInterval) + logger.Printf("Connected to Satel: %s", config.SatelAddr) bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_APITOKEN")) if err != nil { @@ -67,7 +67,7 @@ func main() { } logger.Print("Created Telegram Bot API client") - tgSender := TgSender{bot, s, log.New(os.Stderr, "TgFormatter", log.Lmicroseconds), config.chatIds} + tgSender := TgSender{bot, s, log.New(os.Stderr, "TgFormatter", log.Lmicroseconds), config.ChatIds} tpl := template.Must(template.New("TelegramMessage").Parse(TelegramMessageTemplate)) @@ -84,7 +84,7 @@ func main() { for stopRequested.Load() == false { for e := range FilterByTypeOrIndex( FilterByLastSeen(s.Events, &wg, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)), - &wg, config.allowedTypes, config.allowedIndexes) { + &wg, config.AllowedTypes, config.AllowedIndexes) { logger.Print("Received change from SATEL: ", e) tgEvents <- GenericMessage{e.BasicEvents} } diff --git a/sender_worker.go b/sender_worker.go index 44f58ff..db940e2 100644 --- a/sender_worker.go +++ b/sender_worker.go @@ -83,9 +83,9 @@ func NotifyViaHTTP(events <-chan GenericMessage, config AppConfig, wg *sync.Wait for _, basicElement := range e.Messages { if (basicElement.Index == NotificationPartitionIndex) && (basicElement.Type == satel.ArmedPartition) { if basicElement.Value == ArmedPartition_Armed { - notifyAllHttp(config.armCallbackUrls, logger, wg) + notifyAllHttp(config.ArmCallbackUrls, logger, wg) } else { - notifyAllHttp(config.disarmCallbackUrls, logger, wg) + notifyAllHttp(config.DisarmCallbackUrls, logger, wg) } break inner_arm } @@ -94,7 +94,7 @@ func NotifyViaHTTP(events <-chan GenericMessage, config AppConfig, wg *sync.Wait for _, basicElement := range e.Messages { if basicElement.Type == satel.PartitionAlarm { if basicElement.Value == PartitionAlarm_Alarm { - notifyAllHttp(config.alarmCallbackUrls, logger, wg) + notifyAllHttp(config.AlarmCallbackUrls, logger, wg) break inner_alarm } }