This package is a fork or crypt0train/go-cgminer-api which wasn't updated since 2018.
This repo contains some fixes and improvements like:
- Go module support
- JSON number literal fix for Go 1.14+
- Support for alternative request formats (cgminer has also text-based format)
- Context-based requests (like
CGMiner.SummaryContext()
, etc) - and more!
Important note for crypt0train/go-cgminer-api
users:
This fork introduces some breaking changes:
cgminer.NewCGMiner()
now accepts timeout intime.Duration
format instead of plain seconds inint
- Some field types in stats response were changed from
json.Number
tocgminer.Number
(reason)
# install the library:
go get github.com/x1unix/go-cgminer-api
// Use in your .go code:
import (
cgminer "github.com/x1unix/go-cgminer-api"
)
package main
import (
cgminer "github.com/x1unix/go-cgminer-api"
"time"
"log"
"fmt"
)
func main() {
miner := cgminer.NewCGMiner("localhost", 4028, 2 * time.Second)
stats, err := miner.Stats()
if err != nil {
log.Println(err)
}
fmt.Printf("%s | GHS avg: %0.2f\n", stats.Type, stats.GhsAverage)
// Get generic stats
genericStats := stats.Generic()
// When you connected to Antminer S9
statsS9, _ := stats.S9()
// When you connected to Antminer D3
statsD3, _ := stats.D3()
// When you connected to Antminer L3+
statsL3, _ := stats.L3()
// When you connected to Antminer T9+
statsT9, _ := stats.T9()
}