can't read bee.json from project so it always err

This commit is contained in:
astaxie 2013-07-30 15:35:39 +08:00
parent bf5f0baed7
commit 859c694ce7
2 changed files with 26 additions and 21 deletions

View File

@ -1,12 +0,0 @@
{
"go_install": false,
"dir_structure":{
"controllers": "",
"models": "",
"others": []
},
"main_files":{
"main.go": "",
"others": []
}
}

35
run.go
View File

@ -30,6 +30,21 @@ when the file has changed bee will auto go build and restart the app
`, `,
} }
var defaultJson = `
{
"go_install": false,
"dir_structure":{
"controllers": "",
"models": "",
"others": []
},
"main_files":{
"main.go": "",
"others": []
}
}
`
func init() { func init() {
cmdRun.Run = runApp cmdRun.Run = runApp
} }
@ -85,16 +100,18 @@ func loadConfig() error {
f, err := os.Open("bee.json") f, err := os.Open("bee.json")
if err != nil { if err != nil {
// Use default. // Use default.
return nil err = json.Unmarshal([]byte(defaultJson), &conf)
if err != nil {
return err
}
} else {
defer f.Close()
d := json.NewDecoder(f)
err = d.Decode(&conf)
if err != nil {
return err
}
} }
defer f.Close()
d := json.NewDecoder(f)
err = d.Decode(&conf)
if err != nil {
return err
}
// Set variables. // Set variables.
if len(conf.DirStruct.Controllers) == 0 { if len(conf.DirStruct.Controllers) == 0 {
conf.DirStruct.Controllers = "controllers" conf.DirStruct.Controllers = "controllers"