亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于將 yaml 解組為結構的錯誤

關于將 yaml 解組為結構的錯誤

Go
胡子哥哥 2022-07-04 10:40:53
我想解組一個 []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"`

}

只需更改它即可解決您的問題。


查看完整回答
反對 回復 2022-07-04
  • 1 回答
  • 0 關注
  • 354 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號