Added golangci linting and improved what was required

This commit is contained in:
Nicholas Thompson
2019-03-07 19:04:15 +02:00
committed by ncthompson
parent 206159cdea
commit 2456f45836
15 changed files with 244 additions and 255 deletions

View File

@@ -6,6 +6,7 @@ import (
"net/http"
"github.com/hpdvanwyk/invertergui/frontend"
"github.com/hpdvanwyk/invertergui/mk2if"
"github.com/hpdvanwyk/invertergui/webgui"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -13,7 +14,7 @@ import (
func main() {
addr := flag.String("addr", ":8080", "TCP address to listen on.")
mk2 := NewMk2Mock()
mk2 := mk2if.NewMk2Mock()
gui := webgui.NewWebGui(mk2)
http.Handle("/", frontend.NewStatic())

View File

@@ -1,90 +0,0 @@
package main
import (
"fmt"
"time"
"github.com/hpdvanwyk/invertergui/mk2if"
)
type mock struct {
c chan *mk2if.Mk2Info
}
func NewMk2Mock() mk2if.Mk2If {
tmp := &mock{
c: make(chan *mk2if.Mk2Info, 1),
}
go tmp.genMockValues()
return tmp
}
func genBaseLeds(state mk2if.LEDstate) map[mk2if.Led]mk2if.LEDstate {
return map[mk2if.Led]mk2if.LEDstate{
mk2if.LedMain: state,
mk2if.LedAbsorption: state,
mk2if.LedBulk: state,
mk2if.LedFloat: state,
mk2if.LedInverter: state,
mk2if.LedOverload: state,
mk2if.LedLowBattery: state,
mk2if.LedTemperature: state,
}
}
func (m *mock) GetMk2Info() *mk2if.Mk2Info {
return &mk2if.Mk2Info{
OutCurrent: 2.0,
InCurrent: 2.3,
OutVoltage: 230.0,
InVoltage: 230.1,
BatVoltage: 25,
BatCurrent: -10,
InFrequency: 50,
OutFrequency: 50,
ChargeState: 1,
Errors: nil,
Timestamp: time.Now(),
LEDs: genBaseLeds(mk2if.LedOff),
}
}
func (m *mock) C() chan *mk2if.Mk2Info {
return m.c
}
func (m *mock) Close() {
}
func (m *mock) genMockValues() {
mult := 1.0
ledState := mk2if.LedOff
for {
input := &mk2if.Mk2Info{
OutCurrent: 2.0 * mult,
InCurrent: 2.3 * mult,
OutVoltage: 230.0 * mult,
InVoltage: 230.1 * mult,
BatVoltage: 25 * mult,
BatCurrent: -10 * mult,
InFrequency: 50 * mult,
OutFrequency: 50 * mult,
ChargeState: 1 * mult,
Errors: nil,
Timestamp: time.Now(),
Valid: true,
LEDs: genBaseLeds(ledState),
}
ledState = (ledState + 1) % 3
mult = mult - 0.1
if mult < 0 {
mult = 1.0
}
fmt.Printf("Sending\n")
m.c <- input
time.Sleep(1 * time.Second)
}
}

View File

@@ -3,14 +3,15 @@ package main
import (
"flag"
"fmt"
"github.com/hpdvanwyk/invertergui/mk2if"
"github.com/mikepb/go-serial"
"io"
"log"
"net"
"os"
"os/signal"
"syscall"
"github.com/hpdvanwyk/invertergui/mk2if"
"github.com/mikepb/go-serial"
)
// Basic CLI to serve as example lib usage
@@ -46,10 +47,11 @@ func main() {
}
defer p.Close()
mk2, err := mk2if.NewMk2Connection(p)
defer mk2.Close()
if err != nil {
panic(err)
}
defer mk2.Close()
c := mk2.C()
sigterm := make(chan os.Signal, 1)
signal.Notify(sigterm, syscall.SIGTERM, os.Interrupt)

View File

@@ -76,10 +76,10 @@ func main() {
}
defer p.Close()
mk2, err := mk2if.NewMk2Connection(p)
defer mk2.Close()
if err != nil {
panic(err)
}
defer mk2.Close()
gui := webgui.NewWebGui(mk2)