Make config fields public
This commit is contained in:
parent
12fc45ec38
commit
39ec8f2764
38
config.go
38
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)
|
||||
|
|
8
main.go
8
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}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue