chore: fix semgrep errors
This commit is contained in:
parent
2599c62ac1
commit
00c8852be4
8 changed files with 19 additions and 13 deletions
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
|
@ -82,7 +81,8 @@ func codePrompt(ctx context.Context, devices []tesla.Device) (tesla.Device, stri
|
|||
}
|
||||
|
||||
func captchaPrompt(ctx context.Context, svg io.Reader) (string, error) {
|
||||
tmpFile, err := ioutil.TempFile(os.TempDir(), "evcc-*.svg")
|
||||
// tmpFile, err := ioutil.TempFile(os.TempDir(), "evcc-*.svg")
|
||||
tmpFile, err := os.CreateTemp(os.TempDir(), "evcc-*.svg")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot create temp file: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
|
|
@ -30,7 +32,7 @@ type ModbusResult struct {
|
|||
func (r *ModbusResult) Configuration(handler TaskHandler, res Result) map[string]interface{} {
|
||||
port := handler.(*ModbusHandler).Port
|
||||
cc := map[string]interface{}{
|
||||
"uri": fmt.Sprintf("%s:%d", res.ResultDetails.IP, port),
|
||||
"uri": net.JoinHostPort(res.ResultDetails.IP, strconv.Itoa(port)),
|
||||
"model": "sunspec",
|
||||
"id": r.SlaveID,
|
||||
}
|
||||
|
|
@ -179,7 +181,7 @@ func (h *ModbusHandler) Test(log *util.Logger, in ResultDetails) (res []ResultDe
|
|||
panic("modbus: invalid port")
|
||||
}
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", in.IP, port)
|
||||
addr := net.JoinHostPort(in.IP, strconv.Itoa(port))
|
||||
conn := meters.NewTCP(addr)
|
||||
dev := sunspec.NewDevice("sunspec")
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ package tasks
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
|
|
@ -36,10 +37,10 @@ type MqttHandler struct {
|
|||
}
|
||||
|
||||
func (h *MqttHandler) Test(log *util.Logger, in ResultDetails) []ResultDetails {
|
||||
broker := fmt.Sprintf("%s:%d", in.IP, h.Port)
|
||||
addr := net.JoinHostPort(in.IP, strconv.Itoa(h.Port))
|
||||
|
||||
opt := mqtt.NewClientOptions()
|
||||
opt.AddBroker(broker)
|
||||
opt.AddBroker(addr)
|
||||
opt.SetConnectTimeout(timeout)
|
||||
|
||||
client := mqtt.NewClient(opt)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package tasks
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/util"
|
||||
|
|
@ -37,7 +37,7 @@ type TcpHandler struct {
|
|||
|
||||
func (h *TcpHandler) Test(log *util.Logger, in ResultDetails) (res []ResultDetails) {
|
||||
for _, port := range h.Ports {
|
||||
addr := fmt.Sprintf("%s:%d", in.IP, port)
|
||||
addr := net.JoinHostPort(in.IP, strconv.Itoa(port))
|
||||
conn, err := h.dialer.Dial("tcp", addr)
|
||||
if err == nil {
|
||||
defer conn.Close()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -21,7 +22,7 @@ func removeIfExists(file string) {
|
|||
err = os.Remove(file)
|
||||
}
|
||||
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//go:build gokrazy
|
||||
// +build gokrazy
|
||||
|
||||
package updater
|
||||
|
|
@ -29,7 +30,7 @@ var (
|
|||
// unzipReader transparently unpacks zip files
|
||||
func unzipReader(file io.ReadCloser) (io.ReadCloser, error) {
|
||||
if unzipped, err := gzip.NewReader(file); err == nil {
|
||||
return unzipped, err
|
||||
return unzipped, nil
|
||||
}
|
||||
|
||||
return file, nil
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultPort appends given port to connection if not specified
|
||||
func DefaultPort(conn string, port int) string {
|
||||
if _, _, err := net.SplitHostPort(conn); err != nil {
|
||||
conn = fmt.Sprintf("%s:%d", conn, port)
|
||||
conn = net.JoinHostPort(conn, strconv.Itoa(port))
|
||||
}
|
||||
|
||||
return conn
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ func (v *Ovms) FinishTime() (time.Time, error) {
|
|||
if res, ok := res.(ovmsChargeResponse); err == nil && ok {
|
||||
cef, err := strconv.ParseInt(res.ChargeEtrFull, 0, 64)
|
||||
if err == nil {
|
||||
return time.Now().Add(time.Duration(cef) * time.Minute), err
|
||||
return time.Now().Add(time.Duration(cef) * time.Minute), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue