提交 cb486966 编写于 作者: R Rui Fu 提交者: Jia Zhai

[go function] fix: go function should parse conf content first (#4746)

### Motivation

`pulsar-function-go/conf` package apply `instance-conf-path` with default value `HOME_PATH+github.com/apache/pulsar/pulsar-function-go/conf/conf.yaml`, once function deployed, the running node may not have the yaml conf file exist, then go function will panic with `not found conf file` error.

This PR changed the logic of config parsing, parse `confContent` first, then parse `confFilePath` if `confContent` empty.

(cherry picked from commit 8a3b3af6)
上级 fe687c3c
......@@ -87,15 +87,24 @@ func (c *Conf) GetConf() *Conf {
flag.Usage()
}
if confContent == "" && confFilePath == "" {
log.Errorf("no yaml file or conf content provided")
return nil
}
if confFilePath != "" {
yamlFile, err := ioutil.ReadFile(confFilePath)
if err != nil {
log.Errorf("not found conf file, err:%s", err.Error())
if err == nil {
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Errorf("unmarshal yaml file error:%s", err.Error())
return nil
}
} else if err != nil && os.IsNotExist(err) && confContent == "" {
log.Errorf("conf file not found, no config content provided, err:%s", err.Error())
return nil
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Errorf("unmarshal yaml file error:%s", err.Error())
} else if err != nil && !os.IsNotExist(err) {
log.Errorf("load conf file failed, err:%s", err.Error())
return nil
}
}
......@@ -107,6 +116,7 @@ func (c *Conf) GetConf() *Conf {
return nil
}
}
return c
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册