fix: init config failed

This commit is contained in:
k0a1a 2022-02-24 16:20:20 +08:00
parent b2b477993b
commit 814b109407
2 changed files with 16 additions and 30 deletions

View file

@ -301,7 +301,8 @@ func makeFile(name string, source string) {
makeFileContent(name, []byte(source)) makeFileContent(name, []byte(source))
} }
func makeFileContent(filename string, content []byte) { func makeFileContent(name string, content []byte) {
filename := filepath.Join(config.Conf.Root, name)
err := os.WriteFile(filename, content, 0644) err := os.WriteFile(filename, content, 0644)
if err != nil { if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error())) fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))

View file

@ -105,42 +105,27 @@ func Execute() {
} }
} }
// Boot 设定配置 (这个逻辑有 BUG ) // Boot 设定配置
func Boot() { func Boot() {
if envFile == "" && appPath != "" { root := ""
root, err := filepath.Abs(appPath) if appPath != "" {
r, err := filepath.Abs(appPath)
if err != nil { if err != nil {
exception.New("Root error %s", 500, err.Error()).Throw() exception.New("Root error %s", 500, err.Error()).Throw()
} }
root = r
}
if envFile == "" {
config.Conf = config.LoadFrom(filepath.Join(root, ".env")) config.Conf = config.LoadFrom(filepath.Join(root, ".env"))
config.Conf.Root = root
if config.Conf.Mode == "production" {
config.Production()
} else if config.Conf.Mode == "development" {
config.Development()
}
return
} }
if root != "" {
if envFile != "" && appPath == "" { // 指定环境变量文件
// config.SetEnvFile(envFile)
config.Conf = config.LoadFrom(envFile)
}
if envFile != "" && appPath != "" {
root, err := filepath.Abs(appPath)
if err != nil {
exception.New("Root error %s", 500, err.Error()).Throw()
}
config.Conf = config.LoadFrom(envFile)
config.Conf.Root = root config.Conf.Root = root
if config.Conf.Mode == "production" { }
config.Production() if config.Conf.Mode == "production" {
} else if config.Conf.Mode == "development" { config.Production()
config.Development() } else if config.Conf.Mode == "development" {
} config.Development()
} }
} }