Example #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
}
Example #2
0
// 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)
}