Added golangci linting and improved what was required
This commit is contained in:
committed by
ncthompson
parent
206159cdea
commit
2456f45836
@@ -33,8 +33,9 @@ package webgui
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/hpdvanwyk/invertergui/mk2if"
|
||||
"net/http"
|
||||
|
||||
"github.com/hpdvanwyk/invertergui/mk2if"
|
||||
)
|
||||
|
||||
type muninData struct {
|
||||
@@ -46,7 +47,7 @@ func (w *WebGui) ServeMuninHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
muninDat := <-w.muninRespChan
|
||||
if muninDat.timesUpdated == 0 {
|
||||
rw.WriteHeader(500)
|
||||
rw.Write([]byte("No data to return.\n"))
|
||||
_, _ = rw.Write([]byte("No data to return.\n"))
|
||||
return
|
||||
}
|
||||
calcMuninAverages(&muninDat)
|
||||
@@ -75,7 +76,7 @@ func (w *WebGui) ServeMuninHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(outputBuf, "freqin.value %s\n", tmpInput.InFreq)
|
||||
fmt.Fprintf(outputBuf, "freqout.value %s\n", tmpInput.OutFreq)
|
||||
|
||||
_, err := rw.Write([]byte(outputBuf.String()))
|
||||
_, err := rw.Write(outputBuf.Bytes())
|
||||
if err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
}
|
||||
@@ -171,7 +172,7 @@ freqout.label Out frequency (Hz)
|
||||
|
||||
//Munin only samples once every 5 minutes so averages have to be calculated for some values.
|
||||
func calcMuninValues(muninDat *muninData, newStatus *mk2if.Mk2Info) {
|
||||
muninDat.timesUpdated += 1
|
||||
muninDat.timesUpdated++
|
||||
muninVal := &muninDat.status
|
||||
muninVal.OutCurrent += newStatus.OutCurrent
|
||||
muninVal.InCurrent += newStatus.InCurrent
|
||||
|
||||
@@ -32,6 +32,7 @@ package webgui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -49,7 +50,6 @@ const (
|
||||
)
|
||||
|
||||
type WebGui struct {
|
||||
respChan chan *mk2if.Mk2Info
|
||||
stopChan chan struct{}
|
||||
|
||||
muninRespChan chan muninData
|
||||
@@ -178,14 +178,16 @@ func (w *WebGui) Stop() {
|
||||
func (w *WebGui) dataPoll() {
|
||||
pollChan := w.poller.C()
|
||||
var muninValues muninData
|
||||
s := &mk2if.Mk2Info{}
|
||||
for {
|
||||
select {
|
||||
case s = <-pollChan:
|
||||
case s := <-pollChan:
|
||||
if s.Valid {
|
||||
calcMuninValues(&muninValues, s)
|
||||
w.pu.updatePrometheus(s)
|
||||
w.hub.Broadcast(buildTemplateInput(s))
|
||||
err := w.hub.Broadcast(buildTemplateInput(s))
|
||||
if err != nil {
|
||||
log.Printf("Could not send update to clients: %v", err)
|
||||
}
|
||||
}
|
||||
case w.muninRespChan <- muninValues:
|
||||
zeroMuninValues(&muninValues)
|
||||
|
||||
@@ -32,10 +32,11 @@ package webgui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hpdvanwyk/invertergui/mk2if"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hpdvanwyk/invertergui/mk2if"
|
||||
)
|
||||
|
||||
func TestWebGui(t *testing.T) {
|
||||
@@ -61,27 +62,28 @@ var templateInputTests = []templateTest{
|
||||
InFrequency: 50,
|
||||
OutFrequency: 50,
|
||||
ChargeState: 1,
|
||||
LedListOn: []int{mk2if.LED_MAIN, mk2if.LED_FLOAT},
|
||||
LEDs: map[mk2if.Led]mk2if.LEDstate{mk2if.LedMain: mk2if.LedOn},
|
||||
Errors: nil,
|
||||
Timestamp: fakenow,
|
||||
},
|
||||
output: &templateInput{
|
||||
Error: nil,
|
||||
Date: fakenow.Format(time.RFC1123Z),
|
||||
OutCurrent: "2.000",
|
||||
OutVoltage: "230.000",
|
||||
OutPower: "460.000",
|
||||
InCurrent: "2.300",
|
||||
InVoltage: "230.100",
|
||||
InPower: "529.230",
|
||||
InMinOut: "69.230",
|
||||
BatVoltage: "25.000",
|
||||
BatCurrent: "-10.000",
|
||||
BatPower: "-250.000",
|
||||
InFreq: "50.000",
|
||||
OutFreq: "50.000",
|
||||
BatCharge: "100.000",
|
||||
Leds: []string{"Mains", "Float"}},
|
||||
OutCurrent: "2.00",
|
||||
OutVoltage: "230.00",
|
||||
OutPower: "460.00",
|
||||
InCurrent: "2.30",
|
||||
InVoltage: "230.10",
|
||||
InPower: "529.23",
|
||||
InMinOut: "69.23",
|
||||
BatVoltage: "25.00",
|
||||
BatCurrent: "-10.00",
|
||||
BatPower: "-250.00",
|
||||
InFreq: "50.00",
|
||||
OutFreq: "50.00",
|
||||
BatCharge: "100.00",
|
||||
LedMap: map[string]string{"led_mains": "dot-green"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user