Skip to content

Commit

Permalink
Require Go 1.18 and use generics (evcc-io#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Apr 2, 2022
1 parent cf3b6fb commit 1bfd0f6
Show file tree
Hide file tree
Showing 63 changed files with 450 additions and 771 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ You'll find everything you need in our [documentation](https://docs.evcc.io/) (G

## Build

To build EVCC from source, [Go][2] 1.17 and [Node][3] 16 are required:
To build EVCC from source, [Go][2] 1.18 and [Node][3] 16 are required:

```sh
make
Expand Down
4 changes: 2 additions & 2 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/evcc-io/evcc/util/request"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/philippseith/signalr"
"github.com/thoas/go-funk"
"github.com/samber/lo"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -109,7 +109,7 @@ func NewEasee(user, password, charger string) (*Easee, error) {
}

if len(chargers) != 1 {
return c, fmt.Errorf("cannot determine charger id, found: %v", funk.Map(chargers, func(c easee.Charger) string { return c.ID }))
return c, fmt.Errorf("cannot determine charger id, found: %v", lo.Map(chargers, func(c easee.Charger, _ int) string { return c.ID }))
}

c.charger = chargers[0].ID
Expand Down
4 changes: 2 additions & 2 deletions charger/easee/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/philippseith/signalr"
"github.com/thoas/go-funk"
"golang.org/x/exp/slices"
)

// Logger is a simple logger interface
Expand Down Expand Up @@ -34,7 +34,7 @@ func (l *logger) Log(keyVals ...interface{}) error {
}

if i%2 == 0 {
if funk.Contains(skipped, v) {
if slices.Contains(skipped, v.(string)) {
skip = true
continue
}
Expand Down
1 change: 0 additions & 1 deletion charger/nrgble.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !linux
// +build !linux

package charger

Expand Down
4 changes: 2 additions & 2 deletions charger/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/util/test"
"github.com/thoas/go-funk"
"golang.org/x/exp/slices"
)

var acceptable = []string{
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestTemplates(t *testing.T) {
if values[templates.ParamModbus] != nil {
modbusChoices := tmpl.ModbusChoices()
// we only test one modbus setup
if funk.ContainsString(modbusChoices, templates.ModbusChoiceTCPIP) {
if slices.Contains(modbusChoices, templates.ModbusChoiceTCPIP) {
values[templates.ModbusKeyTCPIP] = true
} else {
values[templates.ModbusKeyRS485TCPIP] = true
Expand Down
16 changes: 8 additions & 8 deletions cmd/configure/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/evcc-io/evcc/util/templates"
"github.com/thoas/go-funk"
stripmd "github.com/writeas/go-strip-markdown"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *CmdConfigure) processDeviceValues(values map[string]interface{}, templa
}

func (c *CmdConfigure) processDeviceCapabilities(capabilitites []string) {
if funk.ContainsString(capabilitites, templates.CapabilitySMAHems) {
if slices.Contains(capabilitites, templates.CapabilitySMAHems) {
c.capabilitySMAHems = true
}
}
Expand All @@ -148,14 +148,14 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
}

// check if sponsorship is required
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
if err := c.askSponsortoken(true, false); err != nil {
return err
}
}

// check if we need to setup an MQTT broker
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementMQTT) {
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementMQTT) {
if c.configuration.config.MQTT == "" {
mqttConfig, err := c.configureMQTT(templateItem)
if err != nil {
Expand All @@ -172,7 +172,7 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
}

// check if we need to setup an EEBUS HEMS
if funk.ContainsString(templateItem.Requirements.EVCC, templates.RequirementEEBUS) {
if slices.Contains(templateItem.Requirements.EVCC, templates.RequirementEEBUS) {
if c.configuration.config.EEBUS == "" {
fmt.Println()
fmt.Println("-- EEBUS -----------------------------------")
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *CmdConfigure) processParamRequirements(param templates.Param) error {
}

// check if sponsorship is required
if funk.ContainsString(param.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
if slices.Contains(param.Requirements.EVCC, templates.RequirementSponsorship) && c.configuration.config.SponsorToken == "" {
if err := c.askSponsortoken(true, true); err != nil {
return err
}
Expand Down Expand Up @@ -384,7 +384,7 @@ func (c *CmdConfigure) fetchElements(deviceCategory DeviceCategory) []templates.
func (c *CmdConfigure) paramChoiceContains(params []templates.Param, name, filter string) bool {
choices := c.paramChoiceValues(params, name)

return funk.ContainsString(choices, filter)
return slices.Contains(choices, filter)
}

// paramChoiceValues provides a list of possible values for a param choice
Expand Down Expand Up @@ -533,7 +533,7 @@ func (c *CmdConfigure) processInputConfig(param templates.Param) string {
}

help := param.Help.String(c.lang)
if funk.ContainsString(param.Requirements.EVCC, templates.RequirementSponsorship) {
if slices.Contains(param.Requirements.EVCC, templates.RequirementSponsorship) {
help = fmt.Sprintf("%s\n\n%s", help, c.localizedString("Requirements_Sponsorship_Feature_Title", nil))
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/configure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/templates"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/thoas/go-funk"
"golang.org/x/exp/slices"
"golang.org/x/text/language"
)

Expand Down Expand Up @@ -320,7 +320,7 @@ func (c *CmdConfigure) configureLoadpoints() {
}

var minValue int = 6
if funk.ContainsString(capabilities, templates.CapabilityISO151182) {
if slices.Contains(capabilities, templates.CapabilityISO151182) {
minValue = 2
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/configure/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util/templates"
"github.com/thoas/go-funk"
stripmd "github.com/writeas/go-strip-markdown"
"golang.org/x/exp/slices"
)

// surveyAskOne asks the user for input
Expand Down Expand Up @@ -49,7 +49,7 @@ func (c *CmdConfigure) askSelection(message string, items []string) (string, int
var selection string
err := c.surveyAskOne(prompt, &selection)

return selection, funk.IndexOf(items, selection), err
return selection, slices.Index(items, selection), err
}

// selectItem selects item from list
Expand Down Expand Up @@ -153,11 +153,11 @@ func (c *CmdConfigure) askValue(q question) string {

validate := func(val interface{}) error {
value := val.(string)
if q.invalidValues != nil && funk.ContainsString(q.invalidValues, value) {
if q.invalidValues != nil && slices.Contains(q.invalidValues, value) {
return errors.New(c.localizedString("ValueError_Used", nil))
}

if q.validValues != nil && !funk.ContainsString(q.validValues, value) {
if q.validValues != nil && !slices.Contains(q.validValues, value) {
return errors.New(c.localizedString("ValueError_Invalid", nil))
}

Expand Down
1 change: 0 additions & 1 deletion cmd/demoport.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !gokrazy
// +build !gokrazy

package cmd

Expand Down
1 change: 0 additions & 1 deletion cmd/demoport_gokrazy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build gokrazy
// +build gokrazy

package cmd

Expand Down
1 change: 0 additions & 1 deletion cmd/gokrazy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build gokrazy
// +build gokrazy

package cmd

Expand Down
1 change: 0 additions & 1 deletion cmd/health.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !windows
// +build !windows

package cmd

Expand Down
15 changes: 10 additions & 5 deletions cmd/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

"github.com/evcc-io/evcc/server"
"github.com/evcc-io/evcc/util"
"github.com/samber/lo"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/thoas/go-funk"
"golang.org/x/exp/slices"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -37,15 +38,19 @@ func runToken(cmd *cobra.Command, args []string) {
if len(conf.Vehicles) == 1 {
vehicleConf = conf.Vehicles[0]
} else if len(args) == 1 {
vehicleConf = funk.Find(conf.Vehicles, func(v qualifiedConfig) bool {
idx := slices.IndexFunc(conf.Vehicles, func(v qualifiedConfig) bool {
return strings.EqualFold(v.Name, args[0])
}).(qualifiedConfig)
})

if idx >= 0 {
vehicleConf = conf.Vehicles[idx]
}
}

if vehicleConf.Name == "" {
vehicles := funk.Map(conf.Vehicles, func(v qualifiedConfig) string {
vehicles := lo.Map(conf.Vehicles, func(v qualifiedConfig, _ int) string {
return v.Name
}).([]string)
})
log.FATAL.Fatalf("vehicle not found, have %v", vehicles)
}

Expand Down
4 changes: 2 additions & 2 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/evcc-io/evcc/provider"
"github.com/evcc-io/evcc/push"
"github.com/evcc-io/evcc/util"
"github.com/thoas/go-funk"
"golang.org/x/exp/slices"

evbus "github.com/asaskevich/EventBus"
"github.com/avast/retry-go/v3"
Expand Down Expand Up @@ -760,7 +760,7 @@ func (lp *LoadPoint) identifyVehicle() {
func (lp *LoadPoint) selectVehicleByID(id string) api.Vehicle {
// find exact match
for _, vehicle := range lp.vehicles {
if funk.ContainsString(vehicle.Identifiers(), id) {
if slices.Contains(vehicle.Identifiers(), id) {
return vehicle
}
}
Expand Down
2 changes: 1 addition & 1 deletion detect/work.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Work(log *util.Logger, num int, hosts []string) []tasks.Result {
// log.INFO.Println(
// "\n" +
// strings.Join(
// funk.Map(taskList.tasks, func(t tasks.Task) string {
// lo.Map(taskList.tasks, func(t tasks.Task) string {
// return fmt.Sprintf("task: %s\ttype: %s\tdepends: %s\n", t.ID, t.Type, t.Depends)
// }).([]string),
// "",
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/evcc-io/evcc

go 1.17
go 1.18

require (
github.com/AlecAivazis/survey/v2 v2.3.2
Expand Down Expand Up @@ -52,6 +52,7 @@ require (
github.com/lorenzodonini/ocpp-go v0.15.0
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40
github.com/manifoldco/promptui v0.9.0
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9
github.com/mitchellh/mapstructure v1.4.3
github.com/mlnoga/rct v0.1.2-0.20220320164346-9f2daa4d6734
github.com/muka/go-bluetooth v0.0.0-20220219050759-674a63b8741a
Expand All @@ -62,19 +63,20 @@ require (
github.com/philippseith/signalr v0.5.3-0.20211205201131-d57b5a34379a
github.com/prometheus/client_golang v1.11.0
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
github.com/samber/lo v1.11.0
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.4.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.2-0.20220212101550-5986bd9c0c19
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942
github.com/thoas/go-funk v0.9.1
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
github.com/volkszaehler/mbmd v0.0.0-20220329124309-22084e041a33
github.com/writeas/go-strip-markdown v2.0.1+incompatible
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
golang.org/x/net v0.0.0-20220325170049-de3da57026de
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
golang.org/x/text v0.3.7
google.golang.org/api v0.73.0
Expand Down Expand Up @@ -122,7 +124,6 @@ require (
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/miekg/dns v1.1.45 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -146,6 +147,7 @@ require (
github.com/spf13/cast v1.4.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/teivah/onecontext v1.3.0 // indirect
github.com/thoas/go-funk v0.9.1
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
Expand Down
Loading

0 comments on commit 1bfd0f6

Please sign in to comment.