-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from camerondurham/dev/move-version-check
Implement #24
- Loading branch information
Showing
7 changed files
with
124 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package util | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
RepositoryUrl = "https://github.com/camerondurham/ch" | ||
RepositoryName = "camerondurham/ch" | ||
) | ||
|
||
type callback func(string) (map[string]interface{}, error) | ||
|
||
func GetGithubAPILatestReleaseURL(repository string) string { | ||
return fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repository) | ||
} | ||
|
||
func GetLatestVersion(getRequest callback, url string) (string, error) { | ||
|
||
data, err := getRequest(url) | ||
if err != nil { | ||
DebugPrint(fmt.Sprintf("error making GET request: %v", err)) | ||
return "", err | ||
} | ||
|
||
tagName := data["tag_name"].(string) | ||
return tagName, nil | ||
} | ||
|
||
func GetRequest(url string) (map[string]interface{}, error) { | ||
res, err := http.Get(url) | ||
if err != nil { | ||
DebugPrint(fmt.Sprintf("error making API request for latest release: %v", err)) | ||
return nil, err | ||
} | ||
|
||
body, err := io.ReadAll(res.Body) | ||
res.Body.Close() | ||
if err != nil { | ||
DebugPrint(fmt.Sprintf("error reading API response body: %v", err)) | ||
return nil, err | ||
} | ||
var data map[string]interface{} | ||
|
||
if err = json.Unmarshal(body, &data); err != nil { | ||
DebugPrint(fmt.Sprintf("error parsing json: %v", err)) | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.