fix: init config failed
This commit is contained in:
parent
b2b477993b
commit
814b109407
2 changed files with 16 additions and 30 deletions
|
|
@ -301,7 +301,8 @@ func makeFile(name string, source string) {
|
|||
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)
|
||||
if err != nil {
|
||||
fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))
|
||||
|
|
|
|||
43
cmd/root.go
43
cmd/root.go
|
|
@ -105,42 +105,27 @@ func Execute() {
|
|||
}
|
||||
}
|
||||
|
||||
// Boot 设定配置 (这个逻辑有 BUG )
|
||||
// Boot 设定配置
|
||||
func Boot() {
|
||||
|
||||
if envFile == "" && appPath != "" {
|
||||
root, err := filepath.Abs(appPath)
|
||||
root := ""
|
||||
if appPath != "" {
|
||||
r, err := filepath.Abs(appPath)
|
||||
if err != nil {
|
||||
exception.New("Root error %s", 500, err.Error()).Throw()
|
||||
}
|
||||
root = r
|
||||
}
|
||||
|
||||
if envFile == "" {
|
||||
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 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)
|
||||
if root != "" {
|
||||
config.Conf.Root = root
|
||||
if config.Conf.Mode == "production" {
|
||||
config.Production()
|
||||
} else if config.Conf.Mode == "development" {
|
||||
config.Development()
|
||||
}
|
||||
|
||||
}
|
||||
if config.Conf.Mode == "production" {
|
||||
config.Production()
|
||||
} else if config.Conf.Mode == "development" {
|
||||
config.Development()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue