working on a global config
This commit is contained in:
@@ -31,6 +31,11 @@ func Execute(log *slog.Logger) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
cobra.OnInitialize(initApplication)
|
||||||
|
|
||||||
rootCmd.Flags().StringP("out", "o", "", "output file")
|
rootCmd.Flags().StringP("out", "o", "", "output file")
|
||||||
rootCmd.Flags().StringP("session", "s", "", "output session info to file")
|
rootCmd.Flags().StringP("session", "s", "", "output session info to file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initApplication() {
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -12,7 +12,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 {
|
if err != nil {
|
||||||
panic("failed to open logging file: " + err.Error())
|
panic("failed to open logging file: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user