1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

update cryptolive

This commit is contained in:
Hossein Mehrabi
2018-06-21 16:03:27 +04:30
parent e0e9e29e91
commit f2ca1c1d5d
5 changed files with 74 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
"github.com/olebedev/config"
@@ -12,7 +13,6 @@ import (
// Config is a pointer to the global config object
var Config *config.Config
var started = false
var baseURL = "https://min-api.cryptocompare.com/data/price"
var ok = true
@@ -27,7 +27,6 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget() *Widget {
started = false
widget := Widget{}
widget.setList()
@@ -51,26 +50,19 @@ func (widget *Widget) setList() {
/* -------------------- Exported Functions -------------------- */
// Refresh & update after interval time
func (widget *Widget) Refresh() {
if started == false {
// this code should run once
go func() {
for {
widget.updateCurrencies()
time.Sleep(time.Duration(widget.RefreshInterval) * time.Second)
}
}()
func (widget *Widget) Refresh(wg *sync.WaitGroup) {
if len(widget.list.items) == 0 {
return
}
started = true
widget.updateCurrencies()
if !ok {
widget.Result = fmt.Sprint("Please check your internet connection!")
return
}
widget.display()
wg.Done()
}
/* -------------------- Unexported Functions -------------------- */
@@ -140,7 +132,6 @@ func (widget *Widget) updateCurrencies() {
setPrices(&jsonResponse, fromCurrency)
}
widget.display()
}
func makeRequest(currency *fromCurrency) *http.Request {