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,57 +27,59 @@ import (
const confVer = 0 const confVer = 0
var defaultConf = `{ var Conf = struct {
"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 {
Version int Version int
// gopm support Gopm gopm
Gopm struct { 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
type gopm struct {
Enable bool Enable bool
Install bool Install bool
} }
// Indicates whether execute "go install" before "go build".
GoInstall bool `json:"go_install" yaml:"go_install"` // dirStruct describes the application's directory structure
DirStruct struct { type dirStruct struct {
WatchAll bool `json:"watch_all" yaml:"watch_all"` WatchAll bool `json:"watch_all" yaml:"watch_all"`
Controllers string Controllers string
Models string Models string
Others []string // Other directories. Others []string // Other directories
} `json:"dir_structure" yaml:"dir_structure"` }
CmdArgs []string `json:"cmd_args" yaml:"cmd_args"`
Envs []string // bale
Bale struct { type bale struct {
Import string Import string
Dirs []string Dirs []string
IngExt []string `json:"ignore_ext" yaml:"ignore_ext"` IngExt []string `json:"ignore_ext" yaml:"ignore_ext"`
} }
Database struct {
// database holds the database connection information
type database struct {
Driver string Driver string
Conn 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. // LoadConfig loads the bee tool configuration.
@ -118,14 +120,8 @@ func LoadConfig() {
return nil return nil
}) })
// In case no configuration file found or an error different than io.EOF,
// fallback to default configuration
if err != io.EOF { if err != io.EOF {
beeLogger.Log.Info("Loading default configuration...") beeLogger.Log.Info("Loading default configuration...")
err = json.Unmarshal([]byte(defaultConf), &Conf)
if err != nil {
return
}
} }
// Check format version // Check format version