0
0
mirror of https://github.com/thegeeklab/wp-github-comment.git synced 2024-11-22 10:10:40 +00:00
wp-github-comment/plugin/utils.go

28 lines
499 B
Go
Raw Normal View History

2020-09-19 22:00:34 +00:00
package plugin
import (
"os"
)
func readStringOrFile(input string) (string, bool, error) {
//nolint:gomnd
2020-09-19 22:00:34 +00:00
if len(input) > 255 {
return input, false, nil
2020-09-19 22:00:34 +00:00
}
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
}
2022-08-05 11:18:24 +00:00
result, err := os.ReadFile(input)
2020-09-19 22:00:34 +00:00
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
}