chore: don't initialise zero-valued structs

This commit is contained in:
andig 2022-08-18 18:33:25 +02:00
parent fce66c644c
commit 14693d2267
35 changed files with 72 additions and 68 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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