create UpdateChecker background task + constants refactoring

This commit is contained in:
Drew Weymouth
2023-03-30 19:19:00 -07:00
parent 2d7e633690
commit cca12d7327
6 changed files with 121 additions and 58 deletions
-18
View File
@@ -2,11 +2,8 @@ package util
import (
"io"
"log"
"math/rand"
"net/http"
"os"
"strings"
"time"
)
@@ -40,18 +37,3 @@ func CopyFile(srcPath, dstPath string) error {
_, err = io.Copy(fout, fin)
return err
}
func LatestVersionTag(latestReleaseURL string) string {
resp, err := http.Head(latestReleaseURL)
if err != nil {
log.Printf("failed to check for newest version: %s", err.Error())
return ""
}
url := resp.Request.URL.String()
url = strings.TrimSuffix(url, "/")
idx := strings.LastIndex(url, "/")
if idx >= len(url)-1 {
return ""
}
return url[idx+1:]
}