示例#1
0
func ParseConfig() error {

	f := configFile
	if FileExists(f) {
		fmt.Println("Using config file at: " + f)
	} else {
		f := configLocation + configFile
		if FileExists(f) {
			fmt.Println("Using config file at: " + f)
		} else {
			return errors.New("Config file not found at: " + f)
		}
	}

	var parser toml.Parser
	Config = parser.ParseFile(f)

	for _, key := range []string{
		"database.database",
		"database.username",
		"database.password",
	} {
		if Config.GetString(key) == "" {
			return errors.New(
				fmt.Sprintf(
					"helpers/config.go: Required config value not found for %s in %s",
					key,
					f,
				),
			)
		}
	}

	return nil
}
示例#2
0
文件: config.go 项目: pzduniak/config
// Load the settings file
func Load(path string) {
	// Print a message (of course we're lying)
	Log.Printf("loaded settings from %s", path)
	// Create a new parser
	var parser toml.Parser
	// Parse the file
	document = parser.ParseFile(path)
}