Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
update go modules, create api package
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Mar 9, 2022
1 parent f8a4276 commit 2a2fefb
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 4 deletions.
80 changes: 80 additions & 0 deletions api/get-latest.go
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
}
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ go 1.17

require (
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/abdfnx/resto v0.1.6
github.com/briandowns/spinner v1.18.1
github.com/muesli/reflow v0.3.0
github.com/spf13/cobra v1.3.0
github.com/tidwall/gjson v1.14.0
)

require (
github.com/fatih/color v1.13.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/text v0.3.7 // indirect
)
Loading

0 comments on commit 2a2fefb

Please sign in to comment.