예제 #1
0
func SaveConfigTo(viperConfig viper.Viper, path string) error {
	err := viperConfig.Unmarshal(&DefaultConfigStruct)
	if err != nil {
		return err
	}

	b, err := json.MarshalIndent(DefaultConfigStruct, "", "    ")
	if err != nil {
		return err
	}

	f, err := os.Create(path)
	if err != nil {
		return err
	}

	defer f.Close()

	f.WriteString(string(b))

	return nil
}