Skip to content

Commit 6637325

Browse files
andigdontbyte
authored andcommitted
Require Go 1.18 and use generics (evcc-io#2116)
1 parent b3b5225 commit 6637325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+450
-771
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You'll find everything you need in our [documentation](https://docs.evcc.io/) (G
4242

4343
## Build
4444

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

4747
```sh
4848
make

charger/easee.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/evcc-io/evcc/util/request"
3434
"github.com/evcc-io/evcc/util/sponsor"
3535
"github.com/philippseith/signalr"
36-
"github.com/thoas/go-funk"
36+
"github.com/samber/lo"
3737
"golang.org/x/oauth2"
3838
)
3939

@@ -109,7 +109,7 @@ func NewEasee(user, password, charger string) (*Easee, error) {
109109
}
110110

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

115115
c.charger = chargers[0].ID

charger/easee/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66

77
"github.com/philippseith/signalr"
8-
"github.com/thoas/go-funk"
8+
"golang.org/x/exp/slices"
99
)
1010

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

3636
if i%2 == 0 {
37-
if funk.Contains(skipped, v) {
37+
if slices.Contains(skipped, v.(string)) {
3838
skip = true
3939
continue
4040
}

charger/nrgble.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux
2-
// +build !linux
32

43
package charger
54

charger/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/evcc-io/evcc/util/templates"
77
"github.com/evcc-io/evcc/util/test"
8-
"github.com/thoas/go-funk"
8+
"golang.org/x/exp/slices"
99
)
1010

1111
var acceptable = []string{
@@ -44,7 +44,7 @@ func TestTemplates(t *testing.T) {
4444
if values[templates.ParamModbus] != nil {
4545
modbusChoices := tmpl.ModbusChoices()
4646
// we only test one modbus setup
47-
if funk.ContainsString(modbusChoices, templates.ModbusChoiceTCPIP) {
47+
if slices.Contains(modbusChoices, templates.ModbusChoiceTCPIP) {
4848
values[templates.ModbusKeyTCPIP] = true
4949
} else {
5050
values[templates.ModbusKeyRS485TCPIP] = true

cmd/configure/helper.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"github.com/evcc-io/evcc/util"
1111
"github.com/evcc-io/evcc/util/sponsor"
1212
"github.com/evcc-io/evcc/util/templates"
13-
"github.com/thoas/go-funk"
1413
stripmd "github.com/writeas/go-strip-markdown"
14+
"golang.org/x/exp/slices"
1515
"gopkg.in/yaml.v3"
1616
)
1717

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

130130
func (c *CmdConfigure) processDeviceCapabilities(capabilitites []string) {
131-
if funk.ContainsString(capabilitites, templates.CapabilitySMAHems) {
131+
if slices.Contains(capabilitites, templates.CapabilitySMAHems) {
132132
c.capabilitySMAHems = true
133133
}
134134
}
@@ -148,14 +148,14 @@ func (c *CmdConfigure) processDeviceRequirements(templateItem templates.Template
148148
}
149149

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

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

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

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

387-
return funk.ContainsString(choices, filter)
387+
return slices.Contains(choices, filter)
388388
}
389389

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

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

cmd/configure/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/evcc-io/evcc/util"
1717
"github.com/evcc-io/evcc/util/templates"
1818
"github.com/nicksnyder/go-i18n/v2/i18n"
19-
"github.com/thoas/go-funk"
19+
"golang.org/x/exp/slices"
2020
"golang.org/x/text/language"
2121
)
2222

@@ -320,7 +320,7 @@ func (c *CmdConfigure) configureLoadpoints() {
320320
}
321321

322322
var minValue int = 6
323-
if funk.ContainsString(capabilities, templates.CapabilityISO151182) {
323+
if slices.Contains(capabilities, templates.CapabilityISO151182) {
324324
minValue = 2
325325
}
326326

cmd/configure/survey.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"github.com/AlecAivazis/survey/v2/terminal"
1212
"github.com/evcc-io/evcc/api"
1313
"github.com/evcc-io/evcc/util/templates"
14-
"github.com/thoas/go-funk"
1514
stripmd "github.com/writeas/go-strip-markdown"
15+
"golang.org/x/exp/slices"
1616
)
1717

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

52-
return selection, funk.IndexOf(items, selection), err
52+
return selection, slices.Index(items, selection), err
5353
}
5454

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

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

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

cmd/demoport.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !gokrazy
2-
// +build !gokrazy
32

43
package cmd
54

cmd/demoport_gokrazy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build gokrazy
2-
// +build gokrazy
32

43
package cmd
54

cmd/gokrazy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build gokrazy
2-
// +build gokrazy
32

43
package cmd
54

cmd/health.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !windows
2-
// +build !windows
32

43
package cmd
54

cmd/token.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66

77
"github.com/evcc-io/evcc/server"
88
"github.com/evcc-io/evcc/util"
9+
"github.com/samber/lo"
910
"github.com/spf13/cobra"
1011
"github.com/spf13/viper"
11-
"github.com/thoas/go-funk"
12+
"golang.org/x/exp/slices"
1213
"golang.org/x/oauth2"
1314
)
1415

@@ -37,15 +38,19 @@ func runToken(cmd *cobra.Command, args []string) {
3738
if len(conf.Vehicles) == 1 {
3839
vehicleConf = conf.Vehicles[0]
3940
} else if len(args) == 1 {
40-
vehicleConf = funk.Find(conf.Vehicles, func(v qualifiedConfig) bool {
41+
idx := slices.IndexFunc(conf.Vehicles, func(v qualifiedConfig) bool {
4142
return strings.EqualFold(v.Name, args[0])
42-
}).(qualifiedConfig)
43+
})
44+
45+
if idx >= 0 {
46+
vehicleConf = conf.Vehicles[idx]
47+
}
4348
}
4449

4550
if vehicleConf.Name == "" {
46-
vehicles := funk.Map(conf.Vehicles, func(v qualifiedConfig) string {
51+
vehicles := lo.Map(conf.Vehicles, func(v qualifiedConfig, _ int) string {
4752
return v.Name
48-
}).([]string)
53+
})
4954
log.FATAL.Fatalf("vehicle not found, have %v", vehicles)
5055
}
5156

core/loadpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/evcc-io/evcc/provider"
1717
"github.com/evcc-io/evcc/push"
1818
"github.com/evcc-io/evcc/util"
19-
"github.com/thoas/go-funk"
19+
"golang.org/x/exp/slices"
2020

2121
evbus "github.com/asaskevich/EventBus"
2222
"github.com/avast/retry-go/v3"
@@ -760,7 +760,7 @@ func (lp *LoadPoint) identifyVehicle() {
760760
func (lp *LoadPoint) selectVehicleByID(id string) api.Vehicle {
761761
// find exact match
762762
for _, vehicle := range lp.vehicles {
763-
if funk.ContainsString(vehicle.Identifiers(), id) {
763+
if slices.Contains(vehicle.Identifiers(), id) {
764764
return vehicle
765765
}
766766
}

detect/work.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Work(log *util.Logger, num int, hosts []string) []tasks.Result {
3939
// log.INFO.Println(
4040
// "\n" +
4141
// strings.Join(
42-
// funk.Map(taskList.tasks, func(t tasks.Task) string {
42+
// lo.Map(taskList.tasks, func(t tasks.Task) string {
4343
// return fmt.Sprintf("task: %s\ttype: %s\tdepends: %s\n", t.ID, t.Type, t.Depends)
4444
// }).([]string),
4545
// "",

go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/evcc-io/evcc
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.2
@@ -52,6 +52,7 @@ require (
5252
github.com/lorenzodonini/ocpp-go v0.15.0
5353
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40
5454
github.com/manifoldco/promptui v0.9.0
55+
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9
5556
github.com/mitchellh/mapstructure v1.4.3
5657
github.com/mlnoga/rct v0.1.2-0.20220320164346-9f2daa4d6734
5758
github.com/muka/go-bluetooth v0.0.0-20220219050759-674a63b8741a
@@ -62,19 +63,20 @@ require (
6263
github.com/philippseith/signalr v0.5.3-0.20211205201131-d57b5a34379a
6364
github.com/prometheus/client_golang v1.11.0
6465
github.com/robertkrimen/otto v0.0.0-20211024170158-b87d35c0b86f
66+
github.com/samber/lo v1.11.0
6567
github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a
6668
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
6769
github.com/spf13/cobra v1.4.0
6870
github.com/spf13/jwalterweatherman v1.1.0
6971
github.com/spf13/pflag v1.0.5
7072
github.com/spf13/viper v1.10.2-0.20220212101550-5986bd9c0c19
7173
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942
72-
github.com/thoas/go-funk v0.9.1
7374
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
7475
github.com/volkszaehler/mbmd v0.0.0-20220329124309-22084e041a33
7576
github.com/writeas/go-strip-markdown v2.0.1+incompatible
7677
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
77-
golang.org/x/net v0.0.0-20220325170049-de3da57026de
78+
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8
79+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
7880
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
7981
golang.org/x/text v0.3.7
8082
google.golang.org/api v0.73.0
@@ -122,7 +124,6 @@ require (
122124
github.com/mattn/go-isatty v0.0.14 // indirect
123125
github.com/mattn/go-runewidth v0.0.13 // indirect
124126
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
125-
github.com/mergermarket/go-pkcs7 v0.0.0-20170926155232-153b18ea13c9
126127
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
127128
github.com/miekg/dns v1.1.45 // indirect
128129
github.com/mitchellh/copystructure v1.2.0 // indirect
@@ -146,6 +147,7 @@ require (
146147
github.com/spf13/cast v1.4.1 // indirect
147148
github.com/subosito/gotenv v1.2.0 // indirect
148149
github.com/teivah/onecontext v1.3.0 // indirect
150+
github.com/thoas/go-funk v0.9.1
149151
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
150152
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
151153
go.opencensus.io v0.23.0 // indirect

0 commit comments

Comments
 (0)