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_r305207583
##########
File path: pulsar-function-go/conf/conf.go
##########
@@ -80,14 +80,34 @@ var (
confContent string
)
+func fileExists(path string) bool {
+ if path == "" {
+ return false
+ }
+ _, err := os.Stat(path)
+ if err != nil && os.IsNotExist(err) {
Review comment:
after some doc reading, seems `os.Stat` check is redundant because
`ioutil.ReadFile` did the same thing. The previous error is because we handle
`ioutil.ReadFile` incorrect, so I did some change to the code, removed
`fileExists` func, `Unmarshal` the yaml file only if `ioutil.ReadFile` returns
no error. Also, if we use `os.Stat`, there might be some extreme condition that
the file will have been changed between `os.Stat` and `ioutil.ReadFile` (ref:
https://groups.google.com/forum/#!msg/golang-nuts/Ayx-BMNdMFo/4rL8FFHr8v4J)
----------------------------------------------------------------
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