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:
2023-09-20 01:15:13 -07:00
parent f692b94c5c
commit 29228bd192
51 changed files with 5008 additions and 1466 deletions

View 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
}