mirror of
https://github.com/MedzikUser/go-cdn
synced 2024-08-15 03:19:36 +00:00
- Discord Bot: Added YML config and moved bot settings from DB to this file - Error logs names has been renames - Discord Bot: Added upload from multi attachments - Update README, Makefile, go.mod and .gitignore
42 lines
741 B
Go
42 lines
741 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, "detect latest 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)
|
|
}
|