From f818c32c23bf6390e29e446b3ff7e56073ad47c1 Mon Sep 17 00:00:00 2001 From: Taylor Fahlman Date: Thu, 28 Jul 2022 11:37:38 -0400 Subject: [PATCH] Fix URL usage for servicelog post templates --- cmd/servicelog/post.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/servicelog/post.go b/cmd/servicelog/post.go index 1ba718c5..6b432b44 100644 --- a/cmd/servicelog/post.go +++ b/cmd/servicelog/post.go @@ -227,6 +227,15 @@ func confirmSend() error { // accessFile returns the contents of a local file or url, and any errors encountered func accessFile(filePath string) ([]byte, error) { + + if utils.IsValidUrl(filePath) { + urlPage, _ := url.Parse(filePath) + if err := utils.IsOnline(*urlPage); err != nil { + return nil, fmt.Errorf("host %q is not accessible", filePath) + } + return utils.CurlThis(urlPage.String()) + } + filePath = filepath.Clean(filePath) if utils.FileExists(filePath) { // template is file on the disk @@ -239,14 +248,6 @@ func accessFile(filePath string) ([]byte, error) { if utils.FolderExists(filePath) { return nil, fmt.Errorf("the provided path %q is a directory, not a file", filePath) } - if utils.IsValidUrl(filePath) { - urlPage, _ := url.Parse(filePath) - if err := utils.IsOnline(*urlPage); err != nil { - return nil, fmt.Errorf("host %q is not accessible", filePath) - } else { - return utils.CurlThis(urlPage.String()) - } - } return nil, fmt.Errorf("cannot read the file %q", filePath) }