我正在尝试读取作为外部参数发送的变量--configFile="",但即使我传递了绝对路径,我也总是找不到错误谁的:var ( c Config conf = c.getConf() app = kingpin.New("exporter", "Exporter for Prometheus.") configFile = app.Flag("configFile", "Configuration file destination (/etc/exporter/config.yaml)").Default("/etc/exporter/config.yaml").String())配置:func (c *Config) getConf() *Config { yamlFile, err := ioutil.ReadFile(string(*configFile)) if err != nil { log.Errorf("yamlFile.Get err #%v ", err) } err = yaml.Unmarshal(yamlFile, c) if err != nil { log.Errorf("Unmarshal: %v", err) } return c}命令/输出:server:/etc/exporter # ./exporter --configFile="/etc/exporter/config.yaml"ERRO[0000] yamlFile.Get err #open : no such file or directoryls -ltr:total 14152-rw------- 1 root root 1334 Sep 25 20:47 config.yaml-rwxrwxr-x 1 root root 14466568 Sep 25 22:03 exporter
1 回答
繁星点点滴滴
TA贡献1803条经验 获得超3个赞
在此处替换代码https://github.com/rafal-szypulka/itm_exporter/blob/master/main.go#L51
和:
conf *Config
在此处替换代码https://github.com/rafal-szypulka/itm_exporter/blob/master/main.go#L354
和:
p := kingpin.MustParse(app.Parse(os.Args[1:]))
conf = c.getConf()
switch p {
- 1 回答
- 0 关注
- 114 浏览
添加回答
举报
0/150
提交
取消