43 lines
1021 B
Go
Raw Permalink Normal View History

2024-05-27 15:10:26 +02:00
package services
import (
"github.com/BurntSushi/toml"
"github.com/joho/godotenv"
"os"
"path"
2024-05-27 15:13:11 +02:00
"wazuh-notify/services/log"
2024-05-27 15:10:26 +02:00
"wazuh-notify/types"
)
func ReadConfig() types.Params {
var configParams types.Params
2024-05-27 15:49:04 +02:00
//Get Path of executable location
2024-05-27 15:10:26 +02:00
baseFilePath, _ := os.Executable()
baseDirPath := path.Dir(baseFilePath)
2024-05-27 15:49:04 +02:00
//Open log file and set first message
2024-05-27 15:10:26 +02:00
log.OpenLogFile(baseDirPath)
2024-05-27 15:49:04 +02:00
//Load .env into environment variables
2024-05-27 15:10:26 +02:00
err := godotenv.Load(path.Join(baseDirPath, "../../etc/.env"))
if err != nil {
log.Log("env failed to load")
godotenv.Load(path.Join(baseDirPath, ".env"))
} else {
log.Log("env loaded")
}
2024-05-27 15:49:04 +02:00
//Read config file
2024-05-27 15:10:26 +02:00
tomlFile, err := os.ReadFile(path.Join(baseDirPath, "../../etc/wazuh-notify-config.toml"))
if err != nil {
log.Log("toml failed to load")
tomlFile, err = os.ReadFile(path.Join(baseDirPath, "wazuh-notify-config.toml"))
}
err = toml.Unmarshal(tomlFile, &configParams)
if err != nil {
print(err)
} else {
log.Log("yaml loaded")
}
return configParams
}