From 14693d2267e36dc0b6ec0094d7a3dd73d692d83c Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 18 Aug 2022 18:33:25 +0200 Subject: [PATCH] chore: don't initialise zero-valued structs --- charger/_blueprint.go | 4 ++-- charger/daheimladen.go | 4 ++-- charger/easee.go | 4 ++-- charger/eebus.go | 4 ++-- charger/evsewifi.go | 4 ++-- charger/fritzdect.go | 4 ++-- charger/go-e.go | 4 ++-- charger/homematic.go | 4 ++-- charger/mcc.go | 4 +++- charger/nrgconnect.go | 4 +++- charger/openwb-pro.go | 4 ++-- charger/shelly.go | 4 ++-- charger/tapo.go | 4 ++-- charger/template.go | 4 ++-- charger/tplink.go | 4 ++-- cmd/config.go | 4 ++-- cmd/token_tronity.go | 4 ++-- hems/ocpp/ocpp.go | 4 ++-- meter/_blueprint.go | 4 ++-- meter/bosch_bpts5_hybrid.go | 4 ++-- meter/fritzdect/fritzdect.go | 4 ++-- meter/homematic.go | 4 ++-- meter/meter.go | 4 ++-- meter/powerwall.go | 4 ++-- meter/shelly.go | 4 ++-- meter/tapo.go | 4 ++-- meter/tasmota.go | 4 ++-- meter/template.go | 4 ++-- meter/tplink.go | 4 ++-- provider/calc.go | 4 ++-- provider/javascript.go | 4 ++-- provider/openwb.go | 4 ++-- vehicle/config.go | 4 ++-- vehicle/template.go | 4 ++-- vehicle/vehicle.go | 4 ++-- 35 files changed, 72 insertions(+), 68 deletions(-) diff --git a/charger/_blueprint.go b/charger/_blueprint.go index 1aaa1c90e..ff521fc4e 100644 --- a/charger/_blueprint.go +++ b/charger/_blueprint.go @@ -37,10 +37,10 @@ func init() { // NewBlueprintFromConfig creates a blueprint charger from generic config func NewBlueprintFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string Cache time.Duration - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/daheimladen.go b/charger/daheimladen.go index c30f5a7ec..6acf24825 100644 --- a/charger/daheimladen.go +++ b/charger/daheimladen.go @@ -28,10 +28,10 @@ func init() { // NewDaheimLadenFromConfig creates a DaheimLaden charger from generic config func NewDaheimLadenFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { Token string StationID string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/easee.go b/charger/easee.go index 44dd43e34..b020575e6 100644 --- a/charger/easee.go +++ b/charger/easee.go @@ -66,11 +66,11 @@ func init() { // NewEaseeFromConfig creates a go-e charger from generic config func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { User string Password string Charger string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/eebus.go b/charger/eebus.go index 9b3fbe458..b0f64f08e 100644 --- a/charger/eebus.go +++ b/charger/eebus.go @@ -42,10 +42,10 @@ func init() { // NewEEBusFromConfig creates an EEBus charger from generic config func NewEEBusFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { Ski string ForcePVLimits bool - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/evsewifi.go b/charger/evsewifi.go index 7b0f1b440..1bca95fc3 100644 --- a/charger/evsewifi.go +++ b/charger/evsewifi.go @@ -30,12 +30,12 @@ func init() { // NewEVSEWifiFromConfig creates a EVSEWifi charger from generic config func NewEVSEWifiFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string Meter struct { Power, Energy, Currents bool } - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/fritzdect.go b/charger/fritzdect.go index 2c71130b7..3dc03c6ce 100644 --- a/charger/fritzdect.go +++ b/charger/fritzdect.go @@ -24,10 +24,10 @@ func init() { // NewFritzDECTFromConfig creates a fritzdect charger from generic config func NewFritzDECTFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { fritzdect.Settings `mapstructure:",squash"` StandbyPower float64 - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/go-e.go b/charger/go-e.go index 3ddb5e9df..2844d8644 100644 --- a/charger/go-e.go +++ b/charger/go-e.go @@ -45,11 +45,11 @@ func init() { // NewGoEFromConfig creates a go-e charger from generic config func NewGoEFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { Token string URI string Cache time.Duration - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/homematic.go b/charger/homematic.go index 48ee721b6..1462a910a 100644 --- a/charger/homematic.go +++ b/charger/homematic.go @@ -18,7 +18,7 @@ func init() { // NewCCUFromConfig creates a Homematic charger from generic config func NewCCUFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string Device string MeterChannel string @@ -26,7 +26,7 @@ func NewCCUFromConfig(other map[string]interface{}) (api.Charger, error) { User string Password string StandbyPower float64 - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/mcc.go b/charger/mcc.go index 03ca8c8e0..a408c3d04 100644 --- a/charger/mcc.go +++ b/charger/mcc.go @@ -69,7 +69,9 @@ func init() { // NewMobileConnectFromConfig creates a MCC charger from generic config func NewMobileConnectFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct{ URI, Password string }{} + var cc struct { + URI, Password string + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err } diff --git a/charger/nrgconnect.go b/charger/nrgconnect.go index 0db7eb585..876bbe417 100644 --- a/charger/nrgconnect.go +++ b/charger/nrgconnect.go @@ -76,7 +76,9 @@ func init() { // NewNRGKickConnectFromConfig creates a NRGKickConnect charger from generic config func NewNRGKickConnectFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct{ URI, Mac, Password string }{} + var cc struct { + URI, Mac, Password string + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err } diff --git a/charger/openwb-pro.go b/charger/openwb-pro.go index 03a781fe8..dffd8ac9c 100644 --- a/charger/openwb-pro.go +++ b/charger/openwb-pro.go @@ -31,10 +31,10 @@ type OpenWBPro struct { // NewOpenWBProFromConfig creates a OpenWBPro charger from generic config func NewOpenWBProFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string Cache time.Duration - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/shelly.go b/charger/shelly.go index b0b85554e..3e44f4ac3 100644 --- a/charger/shelly.go +++ b/charger/shelly.go @@ -20,13 +20,13 @@ func init() { // NewShellyFromConfig creates a Shelly charger from generic config func NewShellyFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string User string Password string Channel int StandbyPower float64 - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/tapo.go b/charger/tapo.go index e87e00c75..d102979da 100644 --- a/charger/tapo.go +++ b/charger/tapo.go @@ -18,12 +18,12 @@ func init() { // NewTapoFromConfig creates a Tapo charger from generic config func NewTapoFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string User string Password string StandbyPower float64 - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/template.go b/charger/template.go index 647a8feb5..4a1d9f8e2 100644 --- a/charger/template.go +++ b/charger/template.go @@ -12,10 +12,10 @@ func init() { } func NewChargerFromTemplateConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { Template string Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/charger/tplink.go b/charger/tplink.go index bc5be79ed..dea31efa7 100644 --- a/charger/tplink.go +++ b/charger/tplink.go @@ -22,10 +22,10 @@ func init() { // NewTPLinkFromConfig creates a TP-Link charger from generic config func NewTPLinkFromConfig(other map[string]interface{}) (api.Charger, error) { - cc := struct { + var cc struct { URI string StandbyPower float64 - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/cmd/config.go b/cmd/config.go index ed913dd3e..5da073c7c 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -209,10 +209,10 @@ func (cp *ConfigProvider) configureVehicles(conf config) error { } // ensure vehicle config has title - ccWithTitle := struct { + var ccWithTitle struct { Title string Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(cc.Other, &ccWithTitle); err != nil { return err diff --git a/cmd/token_tronity.go b/cmd/token_tronity.go index e83cd84c9..9055c6cef 100644 --- a/cmd/token_tronity.go +++ b/cmd/token_tronity.go @@ -112,11 +112,11 @@ func tronityAuthorize(addr string, oc *oauth2.Config) (*oauth2.Token, error) { } func tronityToken(conf config, vehicleConf qualifiedConfig) (*oauth2.Token, error) { - cc := struct { + var cc struct { Credentials vehicle.ClientCredentials RedirectURI string Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(vehicleConf.Other, &cc); err != nil { return nil, err diff --git a/hems/ocpp/ocpp.go b/hems/ocpp/ocpp.go index 0429d6d65..7f8db4421 100644 --- a/hems/ocpp/ocpp.go +++ b/hems/ocpp/ocpp.go @@ -28,10 +28,10 @@ const retryTimeout = 5 * time.Second // New generates OCPP chargepoint client func New(conf map[string]interface{}, site site.API) (*OCPP, error) { - cc := struct { + var cc struct { URI string StationID string - }{} + } if err := util.DecodeOther(conf, &cc); err != nil { return nil, err diff --git a/meter/_blueprint.go b/meter/_blueprint.go index fc63b6abb..6911d4244 100644 --- a/meter/_blueprint.go +++ b/meter/_blueprint.go @@ -20,10 +20,10 @@ func init() { // NewBlueprintFromConfig creates a blueprint meter from generic config func NewBlueprintFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string Cache time.Duration - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/bosch_bpts5_hybrid.go b/meter/bosch_bpts5_hybrid.go index 173b6be04..e3bc98c31 100644 --- a/meter/bosch_bpts5_hybrid.go +++ b/meter/bosch_bpts5_hybrid.go @@ -50,11 +50,11 @@ func init() { // NewBoschBpts5HybridFromConfig creates a Bosch BPT-S 5 Hybrid Meter from generic config func NewBoschBpts5HybridFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string Usage string Cache time.Duration - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/fritzdect/fritzdect.go b/meter/fritzdect/fritzdect.go index a80bdc392..afb499a58 100644 --- a/meter/fritzdect/fritzdect.go +++ b/meter/fritzdect/fritzdect.go @@ -143,11 +143,11 @@ func (c *Connection) getSessionID() error { return err } - v := struct { + var v struct { SID string Challenge string BlockTime string - }{} + } if err = xml.Unmarshal(body, &v); err == nil && v.SID == "0000000000000000" { var challresp string diff --git a/meter/homematic.go b/meter/homematic.go index 19bb84936..0b417f9f5 100644 --- a/meter/homematic.go +++ b/meter/homematic.go @@ -18,7 +18,7 @@ func init() { // NewCCUFromConfig creates a Homematic meter from generic config func NewCCUFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string Device string MeterChannel string @@ -26,7 +26,7 @@ func NewCCUFromConfig(other map[string]interface{}) (api.Meter, error) { User string Password string Usage string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/meter.go b/meter/meter.go index 2c2773013..685675141 100644 --- a/meter/meter.go +++ b/meter/meter.go @@ -17,12 +17,12 @@ func init() { // NewConfigurableFromConfig creates api.Meter from config func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { Power provider.Config Energy *provider.Config // optional SoC *provider.Config // optional Currents []provider.Config // optional - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/powerwall.go b/meter/powerwall.go index 4e1f4e123..75970cffc 100644 --- a/meter/powerwall.go +++ b/meter/powerwall.go @@ -28,9 +28,9 @@ func init() { // NewPowerWallFromConfig creates a PowerWall Powerwall Meter from generic config func NewPowerWallFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI, Usage, User, Password string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/shelly.go b/meter/shelly.go index 1d153fc87..b5c5622f8 100644 --- a/meter/shelly.go +++ b/meter/shelly.go @@ -13,12 +13,12 @@ func init() { // NewShellyFromConfig creates a Shelly charger from generic config func NewShellyFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string User string Password string Channel int - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/tapo.go b/meter/tapo.go index 636338ebb..d1dfbd840 100644 --- a/meter/tapo.go +++ b/meter/tapo.go @@ -13,11 +13,11 @@ func init() { // NewTapoFromConfig creates a tapo meter from generic config func NewTapoFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string User string Password string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/tasmota.go b/meter/tasmota.go index 2a18d1606..cef48d528 100644 --- a/meter/tasmota.go +++ b/meter/tasmota.go @@ -19,12 +19,12 @@ func init() { // NewTasmotaFromConfig creates a Tasmota meter from generic config func NewTasmotaFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string User string Password string Usage string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/template.go b/meter/template.go index c4e1f6ff0..80596f6ef 100644 --- a/meter/template.go +++ b/meter/template.go @@ -12,10 +12,10 @@ func init() { } func NewMeterFromTemplateConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { Template string Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/meter/tplink.go b/meter/tplink.go index 1b504d67c..4c9c35e06 100644 --- a/meter/tplink.go +++ b/meter/tplink.go @@ -13,9 +13,9 @@ func init() { // NewTPLinkFromConfig creates a tapo meter from generic config func NewTPLinkFromConfig(other map[string]interface{}) (api.Meter, error) { - cc := struct { + var cc struct { URI string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/provider/calc.go b/provider/calc.go index cd0651d37..5ec20592a 100644 --- a/provider/calc.go +++ b/provider/calc.go @@ -17,10 +17,10 @@ func init() { // NewCalcFromConfig creates calc provider func NewCalcFromConfig(other map[string]interface{}) (IntProvider, error) { - cc := struct { + var cc struct { Add []Config Mul []Config - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/provider/javascript.go b/provider/javascript.go index dba3ad62d..36e7a2ae3 100644 --- a/provider/javascript.go +++ b/provider/javascript.go @@ -20,10 +20,10 @@ func init() { // NewJavascriptProviderFromConfig creates a HTTP provider func NewJavascriptProviderFromConfig(other map[string]interface{}) (IntProvider, error) { - cc := struct { + var cc struct { VM string Script string - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/provider/openwb.go b/provider/openwb.go index 6fa70058f..12b03e4b6 100644 --- a/provider/openwb.go +++ b/provider/openwb.go @@ -12,9 +12,9 @@ type OpenWBStatus struct { // NewOpenWBStatusProviderFromConfig creates OpenWBStatus from given configuration func NewOpenWBStatusProviderFromConfig(other map[string]interface{}) (func() (string, error), error) { - cc := struct { + var cc struct { Plugged, Charging Config - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err } diff --git a/vehicle/config.go b/vehicle/config.go index 743b708a0..51f217e3d 100644 --- a/vehicle/config.go +++ b/vehicle/config.go @@ -44,10 +44,10 @@ func Types() []string { // NewFromConfig creates vehicle from configuration func NewFromConfig(typ string, other map[string]interface{}) (v api.Vehicle, err error) { - cc := struct { + var cc struct { Cloud bool Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/vehicle/template.go b/vehicle/template.go index 910e45bd0..9e15bc8c1 100644 --- a/vehicle/template.go +++ b/vehicle/template.go @@ -12,10 +12,10 @@ func init() { } func NewVehicleFromTemplateConfig(other map[string]interface{}) (api.Vehicle, error) { - cc := struct { + var cc struct { Template string Other map[string]interface{} `mapstructure:",remain"` - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err diff --git a/vehicle/vehicle.go b/vehicle/vehicle.go index c64ebe6b5..4dba6cf56 100644 --- a/vehicle/vehicle.go +++ b/vehicle/vehicle.go @@ -23,13 +23,13 @@ func init() { // NewConfigurableFromConfig creates a new Vehicle func NewConfigurableFromConfig(other map[string]interface{}) (api.Vehicle, error) { - cc := struct { + var cc struct { embed `mapstructure:",squash"` Soc provider.Config Status *provider.Config Range *provider.Config Odometer *provider.Config - }{} + } if err := util.DecodeOther(other, &cc); err != nil { return nil, err