working on a global config

This commit is contained in:
2026-06-18 17:05:42 +01:00
parent 3e92467beb
commit a980640e40
3 changed files with 58 additions and 1 deletions
+5
View File
@@ -31,6 +31,11 @@ func Execute(log *slog.Logger) {
}
func init() {
cobra.OnInitialize(initApplication)
rootCmd.Flags().StringP("out", "o", "", "output file")
rootCmd.Flags().StringP("session", "s", "", "output session info to file")
}
func initApplication() {
}
+51
View File
@@ -0,0 +1,51 @@
// package config is responsible for the configuration of the application
package config
// NOTE: actually make a package out of this if possible - lets try
import (
"os"
"sync"
"gopkg.in/yaml.v3"
)
var (
instance *ESDICfg
once sync.Once
)
type ESDICfg struct{}
func (cfg *ESDICfg) loadConfiguration() error {
file, err := os.ReadFile("./cfg.yaml")
if err != nil {
return err
}
err = yaml.Unmarshal(file, &instance)
if err != nil {
return err
}
return nil
}
func Setup() error {
instance = &ESDICfg{}
err := instance.loadConfiguration()
if err != nil {
return err
}
return nil
}
func GetCfg() *ESDICfg {
if instance == nil {
panic("configuration instance wasn't initialized")
}
return instance
}
+2 -1
View File
@@ -12,7 +12,8 @@ import (
)
func main() {
output, err := os.OpenFile("./output.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0755)
// NOTE: pass all these things to cobra
output, err := os.OpenFile("./output.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o755)
if err != nil {
panic("failed to open logging file: " + err.Error())
}