go-utils/updater/autoupdate.go

36 lines
542 B
Go
Raw Permalink Normal View History

2021-08-14 20:28:50 +00:00
package updater
import (
"time"
"github.com/MedzikUser/go-utils/common"
)
2021-08-14 20:28:50 +00:00
/*
Auto checks for available updates
This function checking latest version from github and automatically update your program
*/
func (c *Client) AutoUpdater() {
// Check on start
err := c.Update()
2021-08-22 10:16:39 +00:00
common.CheckErr(err, "Auto Updater")
2021-08-14 20:28:50 +00:00
ticker := time.NewTicker(c.CheckEvery)
quit := make(chan struct{})
for {
select {
case <-ticker.C:
err := c.Update()
2021-08-22 10:16:39 +00:00
common.CheckErr(err, "Auto Updater")
2021-08-14 20:28:50 +00:00
case <-quit:
ticker.Stop()
return
}
}
}