pull/15/head 1.0.4
Miguel Mota 6 years ago
parent ca7b105a9b
commit 70748c8e66

@ -503,6 +503,14 @@ Action|Description
- A: Press <kbd>q</kbd> to quit the open view/window. - A: Press <kbd>q</kbd> to quit the open view/window.
- Q: I'm getting the error `open /dev/tty: no such device or address`.
-A: Usually this error occurs when cointop is running as a daemon or slave which means that there is no terminal allocated, so `/dev/tty` doesn't exist for that process. Try running it with the following environment variables:
```bash
DEV_IN=/dev/stdout DEV_OUT=/dev/stdin cointop
```
## Development ## Development
### Go ### Go

@ -69,16 +69,13 @@ type Cointop struct {
convertmenuvisible bool convertmenuvisible bool
} }
// Instance running cointop instance // New initializes cointop
var Instance *Cointop func New() *Cointop {
// Run runs cointop
func Run() {
var debug bool var debug bool
if os.Getenv("DEBUG") != "" { if os.Getenv("DEBUG") != "" {
debug = true debug = true
} }
ct := Cointop{ ct := &Cointop{
api: api.NewCMC(), api: api.NewCMC(),
refreshticker: time.NewTicker(1 * time.Minute), refreshticker: time.NewTicker(1 * time.Minute),
sortby: "rank", sortby: "rank",
@ -142,7 +139,6 @@ func Run() {
convertmenuviewname: "convertmenu", convertmenuviewname: "convertmenu",
currencyconversion: "USD", currencyconversion: "USD",
} }
Instance = &ct
err := ct.setupConfig() err := ct.setupConfig()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -162,7 +158,15 @@ func Run() {
marketcachekey := "market" marketcachekey := "market"
fcache.Get(marketcachekey, &market) fcache.Get(marketcachekey, &market)
ct.cache.Set(marketcachekey, market, 10*time.Second) ct.cache.Set(marketcachekey, market, 10*time.Second)
err = ct.api.Ping()
if err != nil {
log.Fatal(err)
}
return ct
}
// Run runs cointop
func (ct *Cointop) Run() {
g, err := gocui.NewGui(gocui.Output256) g, err := gocui.NewGui(gocui.Output256)
if err != nil { if err != nil {
log.Fatalf("new gocui: %v", err) log.Fatalf("new gocui: %v", err)
@ -195,8 +199,10 @@ func (ct *Cointop) quitView() error {
} }
// Exit safely exit application // Exit safely exit application
func Exit() { func (ct *Cointop) Exit() {
if Instance != nil { if ct.g != nil {
Instance.g.Close() ct.g.Close()
} else {
os.Exit(0)
} }
} }

@ -3,7 +3,6 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"time"
"github.com/miguelmota/cointop/cointop" "github.com/miguelmota/cointop/cointop"
) )
@ -11,27 +10,19 @@ import (
var version = "1.0.1" var version = "1.0.1"
func main() { func main() {
var ver bool var ver, test bool
flag.BoolVar(&ver, "v", false, "Version") flag.BoolVar(&ver, "v", false, "Version")
var test bool
flag.BoolVar(&test, "test", false, "Run test") flag.BoolVar(&test, "test", false, "Run test")
flag.Parse() flag.Parse()
if ver { if ver {
fmt.Println(version) fmt.Println(version)
return } else if test {
doTest()
} else {
cointop.New().Run()
} }
if test {
runTest()
return
}
cointop.Run()
} }
func runTest() { func doTest() {
go func() { cointop.New().Exit()
cointop.Run()
}()
time.Sleep(1 * time.Second)
cointop.Exit()
} }

@ -1,6 +1,7 @@
package coinmarketcap package coinmarketcap
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -19,6 +20,20 @@ func New() *Service {
return &Service{} return &Service{}
} }
// Ping ping API
func (s *Service) Ping() error {
ticker, err := cmc.Ticker(&cmc.TickerOptions{
Symbol: "ETH",
})
if err != nil {
return errors.New("failed to ping")
}
if ticker == nil {
return errors.New("failed to ping")
}
return nil
}
func getLimitedCoinData(convert string, offset int) (map[string]apitypes.Coin, error) { func getLimitedCoinData(convert string, offset int) (map[string]apitypes.Coin, error) {
ret := make(map[string]apitypes.Coin) ret := make(map[string]apitypes.Coin)
max := 100 max := 100

@ -6,6 +6,7 @@ import (
// Interface interface // Interface interface
type Interface interface { type Interface interface {
Ping() error
GetAllCoinData(convert string) (map[string]types.Coin, error) GetAllCoinData(convert string) (map[string]types.Coin, error)
GetCoinGraphData(coin string, start int64, end int64) (types.CoinGraph, error) GetCoinGraphData(coin string, start int64, end int64) (types.CoinGraph, error)
GetGlobalMarketGraphData(start int64, end int64) (types.MarketGraph, error) GetGlobalMarketGraphData(start int64, end int64) (types.MarketGraph, error)

Loading…
Cancel
Save