/go-cgminer-api

Library for accessing the CGMiner API from Go (improved)

Primary LanguageGoMIT LicenseMIT

CGMiner API for Go

Build Status Go Report Card MIT Licence

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!

Breaking changes

Important note for crypt0train/go-cgminer-api users:

This fork introduces some breaking changes:

  • cgminer.NewCGMiner() now accepts timeout in time.Duration format instead of plain seconds in int
  • Some field types in stats response were changed from json.Number to cgminer.Number (reason)

Installation

# install the library:
go get github.com/x1unix/go-cgminer-api

// Use in your .go code:
import (
    cgminer "github.com/x1unix/go-cgminer-api"
)

Quickstart

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()
	
}