Skip to content

Commit

Permalink
changed receivers to pointer receivers, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian1984 committed May 12, 2021
1 parent d9a1785 commit 00b8ed7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,33 @@ import (
func main() {
uc := updatechecker.New("Christian1984", "go-update-checker", "Go Update Checker", "", 0, true, false)
uc.CheckForUpdate("0.0.1")

uc.PrintMessage()
/*
=============================================================
=== INFO: A new update is available for Go Update Checker ===
Version: 0.1.0
Version: 0.0.2
Title: Go Update Checker - 0.1.0 - Initial Release
Title: Go Update Checker - 0.0.2
Description:
Initial Release
Changed receivers to pointer receivers
Download the latest version here:
https://github.com/Christian1984/vfrmap-for-vr/releases
https://github.com/Christian1984/go-update-checker/releases
=============================================================
*/

uc.CheckForUpdate("1.0.0")
uc.CheckForUpdate("0.0.2")
uc.PrintMessage()
/*
========================================================================
=== INFO: You are running the latestest Version of Go Update Checker ===
========================================================================
*/

/* alternatively use uc.Message (type string) in any other context */
}
```

Expand Down
22 changes: 10 additions & 12 deletions updatechecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func New(owner string, repo string, software string, downloadLink string, minDay
return uc
}

func (uc updateChecker) processError(err error) {
func (uc *updateChecker) processError(err error) {
if !uc.Verbose {
return
}

fmt.Println("ERROR: " + err.Error())
}

func (uc updateChecker) requestLatest() (GithubApiResponseData, error) {
func (uc *updateChecker) requestLatest() (GithubApiResponseData, error) {
// call https://api.github.com/repos/{uc.Owner}/{uc.Repo}/releases/latest
var apiResponse GithubApiResponseData

Expand Down Expand Up @@ -86,7 +86,7 @@ func (uc updateChecker) requestLatest() (GithubApiResponseData, error) {
return apiResponse, nil
}

func (uc updateChecker) loadFile() (CheckData, error) {
func (uc *updateChecker) loadFile() (CheckData, error) {
var latestCheck CheckData

file, err := os.Open(Filename)
Expand All @@ -109,7 +109,7 @@ func (uc updateChecker) loadFile() (CheckData, error) {
return latestCheck, nil
}

func (uc updateChecker) writeLatestCheckFile(checkData CheckData) error {
func (uc *updateChecker) writeLatestCheckFile(checkData CheckData) error {
file, jsonErr := json.Marshal(checkData)
if jsonErr != nil {
uc.processError(jsonErr)
Expand All @@ -125,7 +125,7 @@ func (uc updateChecker) writeLatestCheckFile(checkData CheckData) error {
return nil
}

func (uc updateChecker) canCheck(latestCheckTimestamp string) bool {
func (uc *updateChecker) canCheck(latestCheckTimestamp string) bool {
now := time.Now().UTC()
lastCheck, timeErr := time.Parse(DateFormat, latestCheckTimestamp)

Expand Down Expand Up @@ -156,7 +156,7 @@ func (uc updateChecker) canCheck(latestCheckTimestamp string) bool {
return false
}

func (uc updateChecker) updateAvailableMessage(checkData CheckData) string {
func (uc *updateChecker) updateAvailableMessage(checkData CheckData) string {
s := "=== INFO: A new update is available for " + uc.Software + " ==="
bars := strings.Repeat("=", len(s))

Expand All @@ -182,7 +182,7 @@ func (uc updateChecker) updateAvailableMessage(checkData CheckData) string {
bars + "\n"
}

func (uc updateChecker) noUpdateAvailableMessage(checkData CheckData) string {
func (uc *updateChecker) noUpdateAvailableMessage(checkData CheckData) string {
s := "=== INFO: You are running the latestest Version of " + uc.Software + " ==="
bars := strings.Repeat("=", len(s))

Expand All @@ -192,11 +192,11 @@ func (uc updateChecker) noUpdateAvailableMessage(checkData CheckData) string {
bars + "\n"
}

func (uc updateChecker) printMessage() {
func (uc *updateChecker) PrintMessage() {
fmt.Println(uc.Message)
}

func (uc updateChecker) isCurrentVersionOutdated(currentVersion string, availableVersion string) bool {
func (uc *updateChecker) isCurrentVersionOutdated(currentVersion string, availableVersion string) bool {
if uc.Verbose {
fmt.Printf("Comparing current Version %s and available version %s\n", currentVersion, availableVersion)
}
Expand All @@ -222,7 +222,7 @@ func (uc updateChecker) isCurrentVersionOutdated(currentVersion string, availabl
return currOutdated
}

func (uc updateChecker) CheckForUpdate(currentVersion string) {
func (uc *updateChecker) CheckForUpdate(currentVersion string) {
latestCheck, fileErr := uc.loadFile()
if fileErr != nil {
//return false
Expand Down Expand Up @@ -257,6 +257,4 @@ func (uc updateChecker) CheckForUpdate(currentVersion string) {
} else {
uc.Message = uc.noUpdateAvailableMessage(latestCheck)
}

uc.printMessage()
}

0 comments on commit 00b8ed7

Please sign in to comment.