问题描述
我正在尝试读取--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 directory
ls -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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)