2020-09-19 22:00:34 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2021-06-13 16:21:20 +00:00
|
|
|
func readStringOrFile(input string) (string, bool, error) {
|
2020-09-19 22:00:34 +00:00
|
|
|
if len(input) > 255 {
|
2021-06-13 16:21:20 +00:00
|
|
|
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
|
2021-06-13 16:21:20 +00:00
|
|
|
return input, false, nil
|
2020-09-19 22:00:34 +00:00
|
|
|
} else if err != nil {
|
2021-06-13 16:21:20 +00:00
|
|
|
return "", false, err
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
|
|
|
result, err := ioutil.ReadFile(input)
|
|
|
|
if err != nil {
|
2021-06-13 16:21:20 +00:00
|
|
|
return "", true, err
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
2021-06-13 16:21:20 +00:00
|
|
|
return string(result), true, nil
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|