Comments (4)
I found a work-around for this:
func saveConfigToFile(configIns config.Config, configFilePath string) error {
//Save config file
buf := new(bytes.Buffer)
if _, err := configIns.DumpTo(buf, config.JSON); err != nil {
return fmt.Errorf(err.Error())
}
//Pretty print the JSON
var out bytes.Buffer
err := json.Indent(&out, buf.Bytes(), "", " ")
if err != nil {
return fmt.Errorf(err.Error())
}
ioutil.WriteFile(filepath.Join(configFilePath), out.Bytes(), 0755)
return nil
}
If anyone has a better solution, please share that in this thread!
Thanks,
from config.
hi @KiddoV Great.
Can also :
configIns.SetEncoder(config.JSON, func(v interface{}) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
})
from config.
hi @KiddoV
Pretty Print? is config.Export() func ?
Or want pretty print all config data?
from config.
@inhere I meant pretty as JSON for example like above. Like when you export or save config to the file, my JSON would automatically escape newline and indent like Viper
does.
from config.
Related Issues (20)
- [FEAT] Support Encrypted Config File HOT 4
- Add Duration type support HOT 2
- ReloadFiles方法在重载json格式的文件时会发生错误但toml正常
- Support slice with ParseEnv HOT 1
- Panic on missing key/value HOT 1
- More of a question setDecoder manually HOT 3
- yaml Binding ist not working correctly HOT 1
- 结构体中包含数组字段,数组中的子结构体字段设置默认值不生效。 HOT 8
- String Durations are not parsed with ParseTime and ParseEnv
- 监听文件变更,删除配置信息未改变 HOT 6
- Consider the notion of profiles/environments for configuration files HOT 1
- Fail fast for required values HOT 2
- Make parameter expansion scheme great again HOT 1
- 默认值解析空数组时,会自动生成一个元素(附带上默认值) HOT 2
- 你好作者,请问之后有没有修改文件后热重载功能的开发计划? HOT 7
- `time.Duration`支持从`string`加载 HOT 1
- 并发调用 Structure,存在获取不到数据的情况
- hi , 請問在使用yml時 , struct結構體怎給default值? HOT 2
- [FEAT] Support Set with Slice (Array) Index Using Square Brackets? HOT 3
- feat: support parse ENV var on struct default tag
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.