2020-09-19 22:00:34 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2021-06-13 16:21:20 +00:00
|
|
|
func readStringOrFile(input string) (string, bool, error) {
|
2023-02-08 09:13:43 +00:00
|
|
|
//nolint:gomnd
|
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
|
|
|
}
|
2023-02-08 09:13:43 +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
|
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
|
|
|
}
|
2023-02-08 09:13:43 +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 {
|
2021-06-13 16:21:20 +00:00
|
|
|
return "", true, err
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|
2023-02-08 09:13:43 +00:00
|
|
|
|
2021-06-13 16:21:20 +00:00
|
|
|
return string(result), true, nil
|
2020-09-19 22:00:34 +00:00
|
|
|
}
|