mirror of
https://github.com/indig0fox/Arma3-AttendanceTracker.git/
synced 2025-12-08 09:51:47 -06:00
add hemtt support, major refactor
- no longer supports server events - can now more easily build using hemtt - extension vastly improved in both structure and functionality - tested on listen server - includes schema change
This commit is contained in:
65
extension/AttendanceTracker/internal/util/config.go
Normal file
65
extension/AttendanceTracker/internal/util/config.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var ConfigJSON = viper.New()
|
||||
|
||||
func LoadConfig(modulePathDir string) (string, error) {
|
||||
ConfigJSON.SetConfigName("AttendanceTracker.config")
|
||||
ConfigJSON.SetConfigType("json")
|
||||
ConfigJSON.AddConfigPath(".")
|
||||
ConfigJSON.AddConfigPath(modulePathDir)
|
||||
|
||||
ConfigJSON.SetDefault("armaConfig.dbUpdateInterval", "90s")
|
||||
ConfigJSON.SetDefault("armaConfig.debug", true)
|
||||
ConfigJSON.SetDefault("sqlConfig", map[string]interface{}{
|
||||
"mysqlHost": "localhost",
|
||||
"mysqlPort": 3306,
|
||||
"mysqlUser": "root",
|
||||
"mysqlPassword": "password",
|
||||
"mysqlDatabase": "a3attendance",
|
||||
})
|
||||
ConfigJSON.SetDefault("armaConfig", map[string]interface{}{
|
||||
"debug": true,
|
||||
"traceLogToFile": false,
|
||||
"dbUpdateIntervalS": 60,
|
||||
})
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := ConfigJSON.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Config file not found; ignore error if desired
|
||||
return "", fmt.Errorf(
|
||||
"config file not found, using defaults! searched in %s",
|
||||
[]string{
|
||||
ConfigJSON.ConfigFileUsed(),
|
||||
modulePathDir,
|
||||
wd,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// Config file was found but another error was produced
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return "Config loaded successfully!", nil
|
||||
}
|
||||
|
||||
func ConfigArmaFormat() (string, error) {
|
||||
armaConfig := ConfigJSON.GetStringMap("armaConfig")
|
||||
bytes, err := json.Marshal(armaConfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
Reference in New Issue
Block a user