freeznet commented on a change in pull request #4746: [go function] fix: go 
function should parse conf content first
URL: https://github.com/apache/pulsar/pull/4746#discussion_r305247390
 
 

 ##########
 File path: pulsar-function-go/conf/conf.go
 ##########
 @@ -87,16 +87,19 @@ 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())
-                       return nil
-               }
-               err = yaml.Unmarshal(yamlFile, c)
-               if err != nil {
-                       log.Errorf("unmarshal yaml file error:%s", err.Error())
-                       return nil
+               if err == nil {
 
 Review comment:
   how about 
   ```
                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("not found conf file, err:%s", err.Error())
                        return nil
                }
   ```
   so when `ioutil.ReadFile` returns err and `confContent` empty, panic caused, 
otherwise go load `confContent`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to