현재 Exe 경로와 join
This commit is contained in:
@ -3,9 +3,12 @@ package gocommon
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configfileflag = flagx.String("config", "", "")
|
var configfileflag = flagx.String("config", "", "")
|
||||||
@ -16,6 +19,11 @@ func configFilePath() string {
|
|||||||
configfilepath = *configfileflag
|
configfilepath = *configfileflag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(configfilepath, "/") {
|
||||||
|
exe, _ := os.Executable()
|
||||||
|
configfilepath = path.Join(path.Dir(exe), configfilepath)
|
||||||
|
}
|
||||||
|
|
||||||
return configfilepath
|
return configfilepath
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +63,11 @@ func MonitorConfig[T any](onChanged func(newconf *T)) error {
|
|||||||
|
|
||||||
func LoadConfig[T any](outptr *T) error {
|
func LoadConfig[T any](outptr *T) error {
|
||||||
configfilepath := configFilePath()
|
configfilepath := configFilePath()
|
||||||
|
logger.Println("configfilepath : ", configfilepath)
|
||||||
content, err := os.ReadFile(configfilepath)
|
content, err := os.ReadFile(configfilepath)
|
||||||
|
logger.Println("ReadFile : ", string(content))
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
logger.Println("os.IsNotExist :", err)
|
||||||
return os.WriteFile(configfilepath, []byte("{}"), 0666)
|
return os.WriteFile(configfilepath, []byte("{}"), 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user