【发布时间】:2019-08-21 02:35:03
【问题描述】:
我正在介绍一个来自第三方的包,其中包含 struct 和 mapstructure 标签。
我希望这个结构的实例是带有mapstructure指定值的json。我该怎么办?
我可以添加json标签,但是这样做,我修改了包文件,我认为这是一个不好的方式。
type ServiceConfig struct {
// name of the service
Name string `mapstructure:"name"`
// set of endpoint definitions
Endpoints string `mapstructure:"end_points"`
// defafult timeout
Timeout time.Duration `mapstructure:"timeout"`
}
我想得到:
{"name":"sss", "end_points" :"xxx", "timeout" : "120"}
【问题讨论】: