Files
RangerMetrics/extension/internal/settings/settings.go
IndigoFox dc822c4c93 MAJOR rework
- improves a lot on the Go side including better config and logging libraries (including log rotation), better internal package distribution, and new a3go functionality to make data transfer more performant
- SQF side preprocessing of capture data is now minimal - arrays in hashmap format are sent directly to the extension and parsed there to minimize game impact
- CBA custom events are implemented in a better fashion
- README update
- license change
- with performance improvements, the deep customization of integrated metric gathering is removed in return to a single refreshRateMs, defining the interval at which core metrics are captured
- peeled back the list of core metrics to the core information used in troubleshooting and benchmarking
2023-10-10 00:44:50 -07:00

81 lines
1.6 KiB
Go

package settings
import (
"os"
"github.com/indig0fox/a3go/a3interface"
"github.com/spf13/viper"
)
type CBAEventHandlerSetting struct {
Name string `json:"name"`
Description string `json:"description"`
Enabled bool `json:"enabled"`
Bucket string `json:"bucket"`
Measurement string `json:"measurement"`
}
var Active *viper.Viper
func init() {
Active = viper.New()
}
func Setup(
addonFolder string,
) error {
Active.SetConfigName("ifxmetrics.config")
Active.SetConfigType("json")
Active.AddConfigPath(addonFolder)
armaDir, err := os.Getwd()
if err != nil {
return err
}
Active.AddConfigPath(armaDir)
Active.SetDefault("influxdb", map[string]interface{}{
"enabled": false,
"host": "http://localhost:8086",
"token": "",
"org": "",
})
Active.SetDefault("arma3", map[string]interface{}{
"refreshRateMs": 2000,
"debug": "true",
})
Active.SetDefault("cbaEventHandlers", []map[string]interface{}{})
if err := Active.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore error if desired
a3interface.WriteArmaCallback(
"ifxmetrics",
":LOG:",
"WARN",
"Config file not found; using default values.",
)
return nil
} else {
// Config file was found but another error was produced
a3interface.WriteArmaCallback(
"ifxmetrics",
":LOG:",
"ERROR",
err.Error(),
)
return err
}
} else {
a3interface.WriteArmaCallback(
"ifxmetrics",
":LOG:",
"INFO",
"Config file found; using values from config file.",
)
}
return nil
}