keyword everywhere api helper checker – golang and fyne project
keyword everywhere api helper checker – golang and fyne project
source code
package main import ( _ "bytes" _ "encoding/json" _ "fmt" "image/color" "io/ioutil" "net/http" "regexp" _ "strings" "unsafe" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/widget" ) func BytesToString(b []byte) string { return *(*string)(unsafe.Pointer(&b)) } func stripRegex(in string) string { reg, _ := regexp.Compile("[^a-zA-Z0-9 ]+") return reg.ReplaceAllString(in, "") } func main() { url := "https://api.keywordseverywhere.com/v1/account/credits" a := app.New() w := a.NewWindow("Keyword everywhere api Helper") l2 := canvas.NewText("KeywordEveryWhere Api Helper", color.RGBA{R: 255, G: 0, B: 0, A: 255}) l2.TextSize = 23 // get key from user in := widget.NewEntry() in.PlaceHolder = "Enter your API key here" l := widget.NewLabel("Credits left....") btn := widget.NewButton("Check Status", func() { var key = in.Text var bearer = "Bearer " + key // Create a new request using http req, _ := http.NewRequest("GET", url, nil) // add authorization header to the req req.Header.Add("Authorization", bearer) // add app/json header to the req req.Header.Add("Accept", "application/json") // Send req using http Client client := &http.Client{} resp, _ := client.Do(req) defer resp.Body.Close() if resp.StatusCode == 401 { l.Text = "invalid api key" l.Refresh() } else if resp.StatusCode == 200 { body, _ := ioutil.ReadAll(resp.Body) // this function will remove all non alphaNumeric characters var replaceStr = stripRegex(string(body)) l.Text = "Credits left " + replaceStr l.Refresh() } }) w.SetContent(container.NewVBox(l2, in, l, btn)) w.ShowAndRun() }