From 98a30263a63eda6ef2e41627d247d99fef97cfcb Mon Sep 17 00:00:00 2001 From: eccentric Date: Sat, 9 Dec 2023 14:32:53 +0000 Subject: [PATCH] Add config.ini into binary! (0 external files needed once built) --- aid/config.go | 12 +++--------- main.go | 7 ++++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/aid/config.go b/aid/config.go index 427ffc9..4bf3d4b 100644 --- a/aid/config.go +++ b/aid/config.go @@ -1,7 +1,6 @@ package aid import ( - "os" "strconv" "strings" @@ -35,15 +34,10 @@ var ( Config *CS ) -func LoadConfig() { +func LoadConfig(file []byte) { Config = &CS{} - - configPath := "config.ini" - if _, err := os.Stat(configPath); err != nil { - panic("config.ini not found! please rename default.config.ini to config.ini and complete") - } - - cfg, err := ini.Load("config.ini") + + cfg, err := ini.Load(file) if err != nil { panic(err) } diff --git a/main.go b/main.go index 81e76a9..342e98f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + _ "embed" "fmt" "github.com/ectrc/snow/aid" @@ -11,8 +12,12 @@ import ( "github.com/gofiber/fiber/v2" ) + +//go:embed config.ini +var configFile []byte + func init() { - aid.LoadConfig() + aid.LoadConfig(configFile) var device storage.Storage switch aid.Config.Database.Type {