diff --git a/config/module.go b/config/module.go new file mode 100644 index 0000000000000000000000000000000000000000..7fe8ef19b65f662638f94d034ba8324581cc134b --- /dev/null +++ b/config/module.go @@ -0,0 +1,31 @@ +// Copyright 2015, 2016 Eris Industries (UK) Ltd. +// This file is part of Eris-RT + +// Eris-RT is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Eris-RT is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. + +// config defines simple types in a separate package to avoid cyclical imports +package config + +import ( + viper "github.com/spf13/viper" +) + +type ModuleConfig struct { + Module string + Name string + Version string + WorkDir string + DataDir string + Config *viper.Viper +} diff --git a/config/config.go b/core/config.go similarity index 83% rename from config/config.go rename to core/config.go index 099a591971f12c08fe4ace5f7c6c915d7c8e1b7a..ed71d737435270f90d99f8a16919b8ec68bf2012 100644 --- a/config/config.go +++ b/core/config.go @@ -14,66 +14,56 @@ // You should have received a copy of the GNU General Public License // along with Eris-RT. If not, see <http://www.gnu.org/licenses/>. -// config keeps explicit structures on the runtime configuration of +// config.go keeps explicit structures on the runtime configuration of // Eris-DB and all modules. It loads these from the Viper configuration // loaded in `definitions.Do` -package config +package core import ( "fmt" "os" "path" - viper "github.com/spf13/viper" - consensus "github.com/eris-ltd/eris-db/consensus" + config "github.com/eris-ltd/eris-db/config" definitions "github.com/eris-ltd/eris-db/definitions" manager "github.com/eris-ltd/eris-db/manager" util "github.com/eris-ltd/eris-db/util" version "github.com/eris-ltd/eris-db/version" ) -type ModuleConfig struct { - Module string - Name string - Version string - WorkDir string - DataDir string - Config *viper.Viper -} - // LoadConsensusModuleConfig wraps specifically for the consensus module -func LoadConsensusModuleConfig(do *definitions.Do) (ModuleConfig, error) { +func LoadConsensusModuleConfig(do *definitions.Do) (config.ModuleConfig, error) { return loadModuleConfig(do, "consensus") } // LoadApplicationManagerModuleConfig wraps specifically for the application // manager -func LoadApplicationManagerModuleConfig(do *definitions.Do) (ModuleConfig, error) { +func LoadApplicationManagerModuleConfig(do *definitions.Do) (config.ModuleConfig, error) { return loadModuleConfig(do, "manager") } // Generic Module loader for configuration information -func loadModuleConfig(do *definitions.Do, module string) (ModuleConfig, error) { +func loadModuleConfig(do *definitions.Do, module string) (config.ModuleConfig, error) { moduleName := do.Config.GetString("chain." + module + ".name") majorVersion := do.Config.GetInt("chain." + module + ".major_version") minorVersion := do.Config.GetInt("chain." + module + ".minor_version") minorVersionString := version.MakeMinorVersionString(moduleName, majorVersion, minorVersion, 0) if !assertValidModule(module, moduleName, minorVersionString) { - return ModuleConfig{}, fmt.Errorf("%s module %s (%s) is not supported by %s", + return config.ModuleConfig{}, fmt.Errorf("%s module %s (%s) is not supported by %s", module, moduleName, minorVersionString, version.GetVersionString()) } // set up the directory structure for the module inside the data directory workDir := path.Join(do.DataDir, do.Config.GetString("chain." + module + ".relative_root")) if err := util.EnsureDir(workDir, os.ModePerm); err != nil { - return ModuleConfig{}, + return config.ModuleConfig{}, fmt.Errorf("Failed to create module root directory %s.", workDir) } dataDir := path.Join(workDir, "data") if err := util.EnsureDir(dataDir, os.ModePerm); err != nil { - return ModuleConfig{}, + return config.ModuleConfig{}, fmt.Errorf("Failed to create module data directory %s.", dataDir) } // load configuration subtree for module @@ -82,11 +72,11 @@ func loadModuleConfig(do *definitions.Do, module string) (ModuleConfig, error) { // and recovered from or a PR to viper is needed to address this bug. subConfig := do.Config.Sub(moduleName) if subConfig == nil { - return ModuleConfig{}, + return config.ModuleConfig{}, fmt.Errorf("Failed to read configuration section for %s.", moduleName) } - return ModuleConfig { + return config.ModuleConfig { Module : module, Name : moduleName, Version : minorVersionString,