add util func to get latest version tag

This commit is contained in:
Drew Weymouth
2023-03-30 19:16:01 -07:00
parent 5af7744e2d
commit 2d7e633690
2 changed files with 21 additions and 2 deletions
+3 -2
View File
@@ -16,8 +16,9 @@ import (
) )
const ( const (
AppName = "supersonic" AppName = "supersonic"
configFile = "config.toml" configFile = "config.toml"
LatestReleaseURL = "https://github.com/dweymouth/supersonic/releases/latest"
) )
var ( var (
+18
View File
@@ -2,8 +2,11 @@ package util
import ( import (
"io" "io"
"log"
"math/rand" "math/rand"
"net/http"
"os" "os"
"strings"
"time" "time"
) )
@@ -37,3 +40,18 @@ func CopyFile(srcPath, dstPath string) error {
_, err = io.Copy(fout, fin) _, err = io.Copy(fout, fin)
return err 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:]
}