Skip to content

Commit

Permalink
optimize check update
Browse files Browse the repository at this point in the history
  • Loading branch information
likexian committed Apr 29, 2023
1 parent fbac87f commit f1703c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions cmd/whois/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ options:
// checkUpdate checks version update
func checkUpdate(updateMessage chan string, version string) {
checkPoint := "https://release.likexian.com/whois/update"
cacheFile := fmt.Sprintf("%s/whois.update.%s.cache", os.TempDir(), version)
cacheFile := fmt.Sprintf("%s/whois.update.cache", os.TempDir())

req := &xversion.CheckUpdateRequest{
Product: "whois",
Expand All @@ -112,14 +112,18 @@ func checkUpdate(updateMessage chan string, version string) {
ctx := context.Background()
rsp, err := req.Run(ctx)
if err == nil && rsp.Outdated {
emergency := "NOTICE"
if rsp.Emergency {
emergency = "WARNING"
if version != rsp.Current {
_ = os.Remove(cacheFile)
} else {
emergency := "NOTICE"
if rsp.Emergency {
emergency = "WARNING"
}
message := fmt.Sprintf(";; %s: Your version of whois is outdate, the latest is %s.\n",
emergency, rsp.Latest)
message += fmt.Sprintf(";; You can update it by downloading from %s", rsp.ProductURL)
updateMessage <- message
}
message := fmt.Sprintf(";; %s: Your version of whois is outdate, the latest is %s.\n",
emergency, rsp.Latest)
message += fmt.Sprintf(";; You can update it by downloading from %s", rsp.ProductURL)
updateMessage <- message
}

updateMessage <- ""
Expand Down
2 changes: 1 addition & 1 deletion whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Client struct {

// Version returns package version
func Version() string {
return "1.14.7"
return "1.14.8"
}

// Author returns package author
Expand Down

0 comments on commit f1703c8

Please sign in to comment.