mirror of
https://github.com/MedzikUser/go-utils.git
synced 2024-08-15 03:26:56 +00:00
35 lines
542 B
Go
35 lines
542 B
Go
package updater
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/MedzikUser/go-utils/common"
|
|
)
|
|
|
|
/*
|
|
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()
|
|
common.CheckErr(err, "Auto Updater")
|
|
|
|
ticker := time.NewTicker(c.CheckEvery)
|
|
|
|
quit := make(chan struct{})
|
|
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
err := c.Update()
|
|
common.CheckErr(err, "Auto Updater")
|
|
|
|
case <-quit:
|
|
ticker.Stop()
|
|
|
|
return
|
|
}
|
|
}
|
|
}
|