diff --git a/plugin/impl.go b/plugin/impl.go index 977af8f..21d97bb 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -10,6 +10,7 @@ import ( "github.com/google/go-github/v59/github" "github.com/rs/zerolog/log" + "github.com/thegeeklab/wp-plugin-go/file" "golang.org/x/oauth2" ) @@ -38,7 +39,7 @@ func (p *Plugin) Validate() error { } if p.Settings.Message != "" { - if p.Settings.Message, p.Settings.IsFile, err = readStringOrFile(p.Settings.Message); err != nil { + if p.Settings.Message, p.Settings.IsFile, err = file.ReadStringOrFile(p.Settings.Message); err != nil { return fmt.Errorf("error while reading %s: %w", p.Settings.Message, err) } } @@ -58,7 +59,7 @@ func (p *Plugin) Validate() error { p.Settings.Key = fmt.Sprintf("%x", hash) } - if p.Settings.Key, _, err = readStringOrFile(p.Settings.Key); err != nil { + if p.Settings.Key, _, err = file.ReadStringOrFile(p.Settings.Key); err != nil { return fmt.Errorf("error while reading %s: %w", p.Settings.Key, err) } diff --git a/plugin/utils.go b/plugin/utils.go deleted file mode 100644 index 080e86e..0000000 --- a/plugin/utils.go +++ /dev/null @@ -1,27 +0,0 @@ -package plugin - -import ( - "os" -) - -func readStringOrFile(input string) (string, bool, error) { - //nolint:gomnd - if len(input) > 255 { - return input, false, nil - } - - // 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 - } else if err != nil { - return "", false, err - } - - result, err := os.ReadFile(input) - if err != nil { - return "", true, err - } - - return string(result), true, nil -}