현재 Exe 경로와 join
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user