1
0
Fork 0
mirror of https://github.com/MedzikUser/go-cdn synced 2024-08-15 03:19:36 +00:00
go-cdn/update/update.go
Medzik c77de68966 Simple Changes
- Added github workflows and dependabot
- Added goreleaser
- The Automatic Update system has been changed
- Changed DB connect from init to Connect()
2021-07-15 10:47:44 +02:00

42 lines
744 B
Go

package update
import (
"os"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"gitlab.com/gaming0skar123/go/cdn/common"
"gitlab.com/gaming0skar123/go/cdn/config"
)
var log = common.Log
func Update() {
repo := config.GH_Repo
latest, found, err := selfupdate.DetectLatest(repo)
if common.CheckErr(err, "detecting letest version") {
return
}
v := semver.MustParse(config.Version)
if !found || latest.Version.LTE(v) {
return
}
log.Warn("Updating...")
exe, err := os.Executable()
if common.CheckErr(err, "locate executable path") {
return
}
err = selfupdate.UpdateTo(latest.AssetURL, exe)
if common.CheckErr(err, "update binary") {
return
}
log.Info("Updated!")
defer os.Exit(0)
}