This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update go modules, create
api
package
- Loading branch information
Showing
3 changed files
with
133 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
"net/http" | ||
"io/ioutil" | ||
|
||
"github.com/tidwall/gjson" | ||
"github.com/briandowns/spinner" | ||
httpClient "github.com/abdfnx/resto/client" | ||
) | ||
|
||
func GetLatest() string { | ||
url := "https://api.github.com/repos/scmn-dev/secman/releases/latest" | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
|
||
if err != nil { | ||
fmt.Errorf("Error creating request: %s", err.Error()) | ||
} | ||
|
||
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond) | ||
s.Suffix = " 🔍 Checking for updates..." | ||
s.Start() | ||
|
||
client := httpClient.HttpClient() | ||
res, err := client.Do(req) | ||
|
||
if err != nil { | ||
fmt.Printf("Error sending request: %s", err.Error()) | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
b, err := ioutil.ReadAll(res.Body) | ||
|
||
if err != nil { | ||
fmt.Printf("Error reading response: %s", err.Error()) | ||
} | ||
|
||
body := string(b) | ||
|
||
tag_name := gjson.Get(body, "tag_name") | ||
|
||
latestVersion := tag_name.String() | ||
|
||
s.Stop() | ||
|
||
return latestVersion | ||
} | ||
|
||
func GetLatestCore() string { | ||
url := "https://api.secman.dev/latest-core" | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
|
||
if err != nil { | ||
fmt.Errorf("Error creating request: %s", err.Error()) | ||
} | ||
|
||
client := httpClient.HttpClient() | ||
res, err := client.Do(req) | ||
|
||
if err != nil { | ||
fmt.Printf("Error sending request: %s", err.Error()) | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
b, err := ioutil.ReadAll(res.Body) | ||
|
||
if err != nil { | ||
fmt.Printf("Error reading response: %s", err.Error()) | ||
} | ||
|
||
body := string(b) | ||
|
||
return body | ||
} |
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
Oops, something went wrong.