0
0
mirror of https://github.com/thegeeklab/wp-github-comment.git synced 2024-11-24 13:00:41 +00:00
wp-github-comment/plugin/utils.go

25 lines
497 B
Go
Raw Normal View History

2020-09-19 22:00:34 +00:00
package plugin
import (
"io/ioutil"
"os"
)
func readStringOrFile(input string) (string, bool, error) {
2020-09-19 22:00:34 +00:00
if len(input) > 255 {
return input, false, nil
2020-09-19 22:00:34 +00:00
}
// Check if input is a file path
if _, err := os.Stat(input); err != nil && os.IsNotExist(err) {
// No file found => use input as result
return input, false, nil
2020-09-19 22:00:34 +00:00
} else if err != nil {
return "", false, err
2020-09-19 22:00:34 +00:00
}
result, err := ioutil.ReadFile(input)
if err != nil {
return "", true, err
2020-09-19 22:00:34 +00:00
}
return string(result), true, nil
2020-09-19 22:00:34 +00:00
}