From 2fef6d4064b0fba6230105a0b9e323b2b7a0f5c1 Mon Sep 17 00:00:00 2001 From: mountain Date: Sun, 4 Feb 2024 21:03:48 +0900 Subject: [PATCH] =?UTF-8?q?=ED=98=84=EC=9E=AC=20Exe=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=EC=99=80=20join?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reflect_config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/reflect_config.go b/reflect_config.go index 50dd200..6a8a95c 100644 --- a/reflect_config.go +++ b/reflect_config.go @@ -3,9 +3,12 @@ package gocommon import ( "encoding/json" "os" + "path" + "strings" "time" "repositories.action2quare.com/ayo/gocommon/flagx" + "repositories.action2quare.com/ayo/gocommon/logger" ) var configfileflag = flagx.String("config", "", "") @@ -16,6 +19,11 @@ func configFilePath() string { configfilepath = *configfileflag } + if !strings.HasPrefix(configfilepath, "/") { + exe, _ := os.Executable() + configfilepath = path.Join(path.Dir(exe), configfilepath) + } + return configfilepath } @@ -55,8 +63,11 @@ func MonitorConfig[T any](onChanged func(newconf *T)) error { func LoadConfig[T any](outptr *T) error { configfilepath := configFilePath() + logger.Println("configfilepath : ", configfilepath) content, err := os.ReadFile(configfilepath) + logger.Println("ReadFile : ", string(content)) if os.IsNotExist(err) { + logger.Println("os.IsNotExist :", err) return os.WriteFile(configfilepath, []byte("{}"), 0666) }