9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-12-22 03:26:59 +00:00

Properly check env variables in init

This commit is contained in:
Lomanic 2020-10-24 19:05:51 +02:00
parent ee78e7cd15
commit 006ab04b8c

22
main.go
View File

@ -62,14 +62,24 @@ func init() {
if val, _ := strconv.Atoi(port); val > 0 {
config.PORT = port
}
config.MATRIXUSERNAME = os.Getenv("MATRIXUSERNAME")
config.MATRIXACCESSTOKEN = os.Getenv("MATRIXACCESSTOKEN")
config.MATRIXROOM = os.Getenv("MATRIXROOM")
config.MATRIXOPENINGMESSAGE = os.Getenv("MATRIXOPENINGMESSAGE")
config.MATRIXCLOSINGMESSAGE = os.Getenv("MATRIXCLOSINGMESSAGE")
config.MATRIXACCESSTOKEN = os.Getenv("MATRIXACCESSTOKEN")
config.MATRIXUSERNAME = os.Getenv("MATRIXUSERNAME")
config.ESPUSERNAME = os.Getenv("ESPUSERNAME")
config.ESPPASSWORD = os.Getenv("ESPPASSWORD")
if config.MATRIXUSERNAME == "" {
panic("MATRIXUSERNAME is empty")
}
if config.MATRIXACCESSTOKEN == "" {
panic("MATRIXACCESSTOKEN is empty")
}
if config.MATRIXROOM == "" {
panic("MATRIXROOM is empty")
}
@ -79,11 +89,9 @@ func init() {
if config.MATRIXCLOSINGMESSAGE == "" {
panic("MATRIXCLOSINGMESSAGE is empty")
}
if config.MATRIXACCESSTOKEN == "" {
panic("MATRIXACCESSTOKEN is empty")
}
if config.MATRIXUSERNAME == "" {
panic("MATRIXUSERNAME is empty")
if config.ESPUSERNAME == "" {
panic("ESPUSERNAME is empty")
}
if config.ESPPASSWORD == "" {
panic("ESPPASSWORD is empty")