我想解组一个 []byte 变量 int struct prometheusyml。这里是 promethuesyml 和 []byte 变量的定义。type prometheusyml struct { Global global `yaml:"global,omitempty"` ScrapeConfigs []scrapeConfigs `yaml:"scrape_configs,omitempty"`}type global struct { ScrapeInterval string `yaml:"scrape_interval,omitempty"` EvaluationInterval string `yaml:"evaluation_interval,omitempty"`}type scrapeConfigs struct { JobNmaes string `yaml:"job_name,omitempty"` RelabelConfigs []relabelConfigs `yaml:"relabel_configs,omitempty"` MetricsPath string `yaml:"metrics_path,omitempty"` Scheme string `yaml:"scheme,omitempty"` ConsulSdConfigs []consulSdConfigs `yaml:"consul_sd_configs,omitempty"`}type relabelConfigs struct { SourceLabels string `yaml:"source_labels,omitempty"` Action string `yaml:"action,omitempty"` Regex string `yaml:"regex,omitempty"` Replacement string `yaml:"replacement,omitempty"` TargetLabel string `yaml:"target_label,omitempty"`}type consulSdConfigs struct { Server string `yaml:"server,omitempty"` Services []string `yaml:"services,omitempty"`}# my global configglobal: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s).但是当我运行程序时。它显示了错误,这意味着 source_labels 无法解组到结构中。很可能 ["__meta_consul_tags"] 不能翻译成字符串!!!!但是我应该怎么做才能修复这个错误?实际类型是什么?line 11: cannot unmarshal !!seq into string
1 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
source_labelsinrelabel_configs显然是一个数组string。data type所以,你必须替换SourceLabelsfrom stringto []string。那你就可以走了。
type relabelConfigs struct {
SourceLabels []string `yaml:"source_labels,omitempty"`
Action string `yaml:"action,omitempty"`
Regex string `yaml:"regex,omitempty"`
Replacement string `yaml:"replacement,omitempty"`
TargetLabel string `yaml:"target_label,omitempty"`
}
只需更改它即可解决您的问题。
- 1 回答
- 0 关注
- 311 浏览
添加回答
举报
0/150
提交
取消