2020-09-20 00:00:34 +02:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2021-06-13 18:21:20 +02:00
|
|
|
func readStringOrFile(input string) (string, bool, error) {
|
2023-02-08 10:13:43 +01:00
|
|
|
//nolint:gomnd
|
2020-09-20 00:00:34 +02:00
|
|
|
if len(input) > 255 {
|
2021-06-13 18:21:20 +02:00
|
|
|
return input, false, nil
|
2020-09-20 00:00:34 +02:00
|
|
|
}
|
2023-02-08 10:13:43 +01:00
|
|
|
|
2020-09-20 00:00:34 +02: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 18:21:20 +02:00
|
|
|
return input, false, nil
|
2020-09-20 00:00:34 +02:00
|
|
|
} else if err != nil {
|
2021-06-13 18:21:20 +02:00
|
|
|
return "", false, err
|
2020-09-20 00:00:34 +02:00
|
|
|
}
|
2023-02-08 10:13:43 +01:00
|
|
|
|
2022-08-05 13:18:24 +02:00
|
|
|
result, err := os.ReadFile(input)
|
2020-09-20 00:00:34 +02:00
|
|
|
if err != nil {
|
2021-06-13 18:21:20 +02:00
|
|
|
return "", true, err
|
2020-09-20 00:00:34 +02:00
|
|
|
}
|
2023-02-08 10:13:43 +01:00
|
|
|
|
2021-06-13 18:21:20 +02:00
|
|
|
return string(result), true, nil
|
2020-09-20 00:00:34 +02:00
|
|
|
}
|