Skip to content

Commit

Permalink
fix error in update function
Browse files Browse the repository at this point in the history
  • Loading branch information
sudosammy committed Jun 10, 2018
1 parent 9301291 commit 5b66071
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
38 changes: 21 additions & 17 deletions knary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
)

const (
VERSION = "1.0.0"
VERSION = "1.0.1"
GITHUB = "https://github.com/sudosammy/knary"
GITHUB_VERSION = "https://raw.githubusercontent.com/sudosammy/knary/master/VERSION"
)

func main() {
Expand Down Expand Up @@ -76,7 +77,7 @@ func main() {
printy("Listening for http(s)://*." + os.Getenv("CANARY_DOMAIN") + " requests", 1)
}
if os.Getenv("DNS") == "true" {
printy("Listening for *." + os.Getenv("CANARY_DOMAIN") + " DNS requests", 1)
printy("Listening for *.dns." + os.Getenv("CANARY_DOMAIN") + " DNS requests", 1)
}
printy("Posting to webhook: " + os.Getenv("SLACK_WEBHOOK"), 1)

Expand Down Expand Up @@ -470,7 +471,7 @@ func checkUpdate() bool {
return false
}

response, err := http.Get(GITHUB + "/master/VERSION")
response, err := http.Get(GITHUB_VERSION)

if err != nil {
updFail := "Could not check for updates: " + err.Error()
Expand All @@ -481,22 +482,25 @@ func checkUpdate() bool {

defer response.Body.Close()
scanner := bufio.NewScanner(response.Body) // refusing to import ioutil
current, err := semver.Make(scanner.Text())

if err != nil {
updFail := "Could not check for updates. GitHub response !semver format"
printy(updFail, 2)
logger(updFail)
return false
for scanner.Scan() { // foreach line
current, err := semver.Make(scanner.Text())

if err != nil {
updFail := "Could not check for updates. GitHub response !semver format"
printy(updFail, 2)
logger(updFail)
return false
}

if running.Compare(current) != 0 {
updMsg := ":warning: Your version of knary is *" + VERSION + "* & the latest is *" + current.String() + "* - upgrade your binary here: " + GITHUB
printy(updMsg, 2)
logger(updMsg)
go sendMsg(updMsg)
return true
}
}

if running.Compare(current) != 0 {
updMsg := ":warning: Your version of knary is *" + VERSION + "* & the latest is *" + current.String() + "* - upgrade your binary here: " + GITHUB
printy(updMsg, 2)
logger(updMsg)
go sendMsg(updMsg)
return true
}

return false
}

0 comments on commit 5b66071

Please sign in to comment.