changeset 5683:31973f6f5cca sr-v2

Get rid of deprecation warnings from staticcheck.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 11 Feb 2024 21:37:00 +0100
parents 33499bd1b829
children 536e842d9bfa
files pkg/controllers/proxy.go pkg/controllers/shapestretches.go pkg/controllers/system.go pkg/imports/wg.go pkg/misc/http.go pkg/soap/soap.go pkg/soap/validate.go pkg/wfs/global.go
diffstat 8 files changed, 19 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/proxy.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/controllers/proxy.go	Sun Feb 11 21:37:00 2024 +0100
@@ -21,7 +21,6 @@
 	"encoding/base64"
 	"encoding/xml"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"net/url"
 	"regexp"
@@ -138,7 +137,7 @@
 				if r2, ok := r.(io.ReadCloser); ok {
 					return r2, nil
 				}
-				return ioutil.NopCloser(r), nil
+				return io.NopCloser(r), nil
 			},
 			func(w io.Writer) (io.WriteCloser, error) {
 				if w2, ok := w.(io.WriteCloser); ok {
--- a/pkg/controllers/shapestretches.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/controllers/shapestretches.go	Sun Feb 11 21:37:00 2024 +0100
@@ -18,7 +18,6 @@
 	"database/sql"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -188,7 +187,7 @@
 
 	tmp := config.TmpDir()
 
-	dir, err := ioutil.TempDir(tmp, "stretch-download")
+	dir, err := os.MkdirTemp(tmp, "stretch-download")
 	if err != nil {
 		http.Error(
 			rw, fmt.Sprintf("Cannot create temp dir: %v.", err),
--- a/pkg/controllers/system.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/controllers/system.go	Sun Feb 11 21:37:00 2024 +0100
@@ -18,8 +18,8 @@
 	"context"
 	"database/sql"
 	"fmt"
-	"io/ioutil"
 	"net/http"
+	"os"
 	"regexp"
 	"strings"
 	"sync"
@@ -90,7 +90,7 @@
 
 	var txt []byte
 
-	if txt, err = ioutil.ReadFile(path); err != nil {
+	if txt, err = os.ReadFile(path); err != nil {
 		return
 	}
 
@@ -112,7 +112,7 @@
 	}
 
 	var data []byte
-	if data, err = ioutil.ReadFile(cfg); err != nil {
+	if data, err = os.ReadFile(cfg); err != nil {
 		return
 	}
 
--- a/pkg/imports/wg.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/imports/wg.go	Sun Feb 11 21:37:00 2024 +0100
@@ -180,7 +180,7 @@
 `
 )
 
-var continueErr = errors.New("continue")
+var errContinue = errors.New("continue")
 
 // Do implements the actual import.
 func (wg *WaterwayGauge) Do(
@@ -361,7 +361,7 @@
 				case err != nil:
 					feedback.Error(pgxutils.ReadableError{Err: err}.Error())
 					unchanged++
-					return continueErr
+					return errContinue
 				case isNew:
 					var lu *time.Time
 					if dr.Lastupdate != nil {
@@ -388,7 +388,7 @@
 					); err != nil {
 						key := pgxutils.ReadableError{Err: err}.Error()
 						databaseErrors[key] = append(databaseErrors[key], isrs)
-						return continueErr
+						return errContinue
 					}
 					newGauges = append(newGauges, isrs)
 					//feedback.Info("insert new version")
@@ -417,12 +417,12 @@
 					case err2 == sql.ErrNoRows:
 						//feedback.Info("unchanged")
 						unchanged++
-						return continueErr
+						return errContinue
 					case err2 != nil:
 						key := pgxutils.ReadableError{Err: err2}.Error()
 						databaseErrors[key] = append(databaseErrors[key], isrs)
 						unchanged++
-						return continueErr
+						return errContinue
 					default:
 						updatedGauges = append(updatedGauges, isrs)
 						//feedback.Info("update")
@@ -477,7 +477,7 @@
 					key := pgxutils.ReadableError{Err: err}.Error()
 					databaseErrors[key] = append(databaseErrors[key], isrs)
 					unchanged++
-					return continueErr
+					return errContinue
 				}
 
 				// "Upsert" reference water levels
@@ -529,7 +529,7 @@
 				return tx.Commit()
 			}()
 
-			if err != nil && err != continueErr {
+			if err != nil && err != errContinue {
 				return err, nil
 			}
 		}
--- a/pkg/misc/http.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/misc/http.go	Sun Feb 11 21:37:00 2024 +0100
@@ -17,7 +17,6 @@
 	"bufio"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"os"
 	"path/filepath"
@@ -54,7 +53,7 @@
 	}
 	defer f.Close()
 
-	dir, err := ioutil.TempDir(config.TmpDir(), field)
+	dir, err := os.MkdirTemp(config.TmpDir(), field)
 	if err != nil {
 		return "", err
 	}
--- a/pkg/soap/soap.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/soap/soap.go	Sun Feb 11 21:37:00 2024 +0100
@@ -19,7 +19,7 @@
 	"crypto/tls"
 	"encoding/xml"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"math/rand"
 	"net"
 	"net/http"
@@ -311,7 +311,7 @@
 	defer res.Body.Close()
 
 	if res.StatusCode < http.StatusOK || res.StatusCode > 299 {
-		rawbody, err := ioutil.ReadAll(res.Body)
+		rawbody, err := io.ReadAll(res.Body)
 		var body string
 		if err == nil {
 			if len(rawbody) > 1024 {
@@ -325,7 +325,7 @@
 			res.StatusCode, http.StatusText(res.StatusCode), body)
 	}
 
-	rawbody, err := ioutil.ReadAll(res.Body)
+	rawbody, err := io.ReadAll(res.Body)
 	if err != nil {
 		return err
 	}
--- a/pkg/soap/validate.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/soap/validate.go	Sun Feb 11 21:37:00 2024 +0100
@@ -18,7 +18,6 @@
 	"encoding/xml"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -99,7 +98,7 @@
 		} `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
 	}
 
-	content, err := ioutil.ReadAll(r)
+	content, err := io.ReadAll(r)
 	if err != nil {
 		return err
 	}
@@ -127,7 +126,7 @@
 
 	cmd.Stdin = bytes.NewReader(content)
 	cmd.Stderr = &stderr
-	cmd.Stdout = ioutil.Discard
+	cmd.Stdout = io.Discard
 
 	if err := cmd.Start(); err != nil {
 		return err
--- a/pkg/wfs/global.go	Sun Feb 11 21:26:22 2024 +0100
+++ b/pkg/wfs/global.go	Sun Feb 11 21:37:00 2024 +0100
@@ -17,7 +17,6 @@
 	"bufio"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -131,7 +130,7 @@
 	}
 
 	tmpDir := config.TmpDir()
-	dlDir, err := ioutil.TempDir(tmpDir, "wfs-downloads")
+	dlDir, err := os.MkdirTemp(tmpDir, "wfs-downloads")
 	if err != nil {
 		return err
 	}