This makes sure default config is always loaded

When loading configuration from Beefile or bee.json default values are
not loaded. This fixes that behaviour and makes sure defaults are loaded
and overrided if present in Beefile/bee.json.
This commit is contained in:
Faissal Elamraoui 2017-03-13 20:34:04 +01:00
parent 426237fefe
commit e57cc7b94e
1 changed files with 51 additions and 55 deletions

View File

@ -27,58 +27,60 @@ import (
const confVer = 0
var defaultConf = `{
"version": 0,
"gopm": {
"enable": false,
"install": false
},
"go_install": true,
"dir_structure": {
"watch_all": false,
"controllers": "",
"models": "",
"others": []
},
"cmd_args": [],
"envs": [],
"database": {
"driver": "mysql"
},
"enable_reload": false,
"enable_notification": true
}
`
var Conf struct {
var Conf = struct {
Version int
Gopm gopm
GoInstall bool `json:"go_install" yaml:"go_install"` // Indicates whether execute "go install" before "go build".
DirStruct dirStruct `json:"dir_structure" yaml:"dir_structure"`
CmdArgs []string `json:"cmd_args" yaml:"cmd_args"`
Envs []string
Bale bale
Database database
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
}{
GoInstall: true,
DirStruct: dirStruct{
Others: []string{},
},
CmdArgs: []string{},
Envs: []string{},
Bale: bale{
Dirs: []string{},
IngExt: []string{},
},
Database: database{
Driver: "mysql",
},
EnableNotification: true,
}
// gopm support
Gopm struct {
type gopm struct {
Enable bool
Install bool
}
// Indicates whether execute "go install" before "go build".
GoInstall bool `json:"go_install" yaml:"go_install"`
DirStruct struct {
// dirStruct describes the application's directory structure
type dirStruct struct {
WatchAll bool `json:"watch_all" yaml:"watch_all"`
Controllers string
Models string
Others []string // Other directories.
} `json:"dir_structure" yaml:"dir_structure"`
CmdArgs []string `json:"cmd_args" yaml:"cmd_args"`
Envs []string
Bale struct {
Others []string // Other directories
}
// bale
type bale struct {
Import string
Dirs []string
IngExt []string `json:"ignore_ext" yaml:"ignore_ext"`
}
Database struct {
// database holds the database connection information
type database struct {
Driver string
Conn string
}
EnableReload bool `json:"enable_reload" yaml:"enable_reload"`
EnableNotification bool `json:"enable_notification" yaml:"enable_notification"`
}
// LoadConfig loads the bee tool configuration.
// It looks for Beefile or bee.json in the current path,
@ -118,14 +120,8 @@ func LoadConfig() {
return nil
})
// In case no configuration file found or an error different than io.EOF,
// fallback to default configuration
if err != io.EOF {
beeLogger.Log.Info("Loading default configuration...")
err = json.Unmarshal([]byte(defaultConf), &Conf)
if err != nil {
return
}
}
// Check format version