Cleanup code for Go 1.19

This commit is contained in:
tidwall 2022-09-12 17:06:27 -07:00
parent 023433a963
commit dd11eded5c
21 changed files with 35 additions and 48 deletions

View File

@ -221,7 +221,7 @@ func main() {
}
subtract = true
for i := range testsArr {
if strings.ToLower(testsArr[i]) == strings.ToLower(test[1:]) {
if strings.EqualFold(testsArr[i], test[1:]) {
testsArr = append(testsArr[:i], testsArr[i+1:]...)
break
}

View File

@ -9,12 +9,11 @@ import (
"runtime"
"runtime/debug"
"github.com/tidwall/resp"
"github.com/yuin/gopher-lua"
"strings"
)
var errCmdNotSupported = errors.New("command not supported in scripts")
"github.com/tidwall/resp"
lua "github.com/yuin/gopher-lua"
)
func Sha1Sum(s string) string {
h := sha1.New()
@ -271,7 +270,7 @@ func testLua() {
start = runMany(luaState, start, 100)
printMemStats()
start = runMany(luaState, start, 1000)
_ = runMany(luaState, start, 1000)
printMemStats()
luaState.Close()

View File

@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
_ "net/http/pprof"
@ -108,7 +107,7 @@ Developer Options:
log.Fatal(err)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
@ -294,7 +293,7 @@ Developer Options:
var logw io.Writer = os.Stderr
if quiet {
logw = ioutil.Discard
logw = io.Discard
}
log.SetOutput(logw)
@ -390,7 +389,7 @@ Developer Options:
}
defer pidcleanup()
if pidfile != "" {
ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0666)
os.WriteFile(pidfile, []byte(fmt.Sprintf("%d\n", os.Getpid())), 0666)
}
c := make(chan os.Signal, 1)

View File

@ -1,4 +1,4 @@
// +build ignore
//go:build ignore
package core

View File

@ -13,5 +13,5 @@ perl -pe '
' commands.go > commands_gen.go
# remove the ignore
sed -i -e 's/\/\/ +build ignore/\/\/ This file was autogenerated. DO NOT EDIT./g' commands_gen.go
sed -i -e 's/\/\/go:build ignore/\/\/ This file was autogenerated. DO NOT EDIT./g' commands_gen.go
rm -rf commands_gen.go-e

2
go.mod
View File

@ -107,7 +107,7 @@ require (
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
google.golang.org/protobuf v1.26.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
)

3
go.sum
View File

@ -689,8 +689,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -14,6 +14,7 @@ func New(dl time.Time) *Deadline {
}
// Check the deadline and panic when reached
//
//go:noinline
func (dl *Deadline) Check() {
if dl == nil || dl.unixNano == 0 {

View File

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"
)
@ -54,7 +53,7 @@ func (conn *HTTPConn) Send(msg string) error {
// close the connection to reuse it
defer resp.Body.Close()
// discard response
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
return err
}
// Only allow responses with status code 200, 201, and 202

View File

@ -5,7 +5,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"os"
"sync"
"time"
@ -192,7 +191,7 @@ func loadClientTLSCert(KeyFile, CertFile string) ([]tls.Certificate, error) {
func loadRootTLSCert(CACertFile string) (x509.CertPool, error) {
// Load CA cert
caCert, err := ioutil.ReadFile(CACertFile)
caCert, err := os.ReadFile(CACertFile)
if err != nil {
return x509.CertPool{}, err

View File

@ -4,8 +4,8 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"math/rand"
"os"
"sync"
"time"
@ -76,7 +76,7 @@ func (conn *MQTTConn) Send(msg string) error {
}
if conn.ep.MQTT.CACertFile != "" {
// Load CA cert
caCert, err := ioutil.ReadFile(conn.ep.MQTT.CACertFile)
caCert, err := os.ReadFile(conn.ep.MQTT.CACertFile)
if err != nil {
return err
}

View File

@ -36,7 +36,6 @@ var ErrBadPattern = errors.New("syntax error in pattern")
//
// On Windows, escaping is disabled. Instead, '\\' is treated as
// path separator.
//
func wildcardMatch(pattern, name string) (matched bool, err error) {
Pattern:
for len(pattern) > 0 {

View File

@ -2,7 +2,7 @@ package log
import (
"bytes"
"io/ioutil"
"io"
"strings"
"testing"
@ -189,7 +189,7 @@ func TestLogJSON(t *testing.T) {
func BenchmarkLogPrintf(t *testing.B) {
LogJSON = false
Level = 1
SetOutput(ioutil.Discard)
SetOutput(io.Discard)
t.ResetTimer()
for i := 0; i < t.N; i++ {
Printf("X %s", "Y")
@ -208,7 +208,7 @@ func BenchmarkLogJSONPrintf(t *testing.B) {
logger := zap.New(
zapcore.NewCore(
enc,
zapcore.AddSync(ioutil.Discard),
zapcore.AddSync(io.Discard),
zap.DebugLevel,
)).Sugar()

View File

@ -2,7 +2,6 @@ package server
import (
"encoding/json"
"io/ioutil"
"os"
"strconv"
"strings"
@ -71,7 +70,7 @@ type Config struct {
func loadConfig(path string) (*Config, error) {
var json string
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
@ -217,7 +216,7 @@ func (config *Config) write(writeProperties bool) {
panic(err)
}
data = append(data, '\n')
err = ioutil.WriteFile(config.path, data, 0600)
err = os.WriteFile(config.path, data, 0600)
if err != nil {
panic(err)
}
@ -327,11 +326,11 @@ func (config *Config) setProperty(name, value string, fromLoad bool) error {
config._logConfig = value
}
case ReplicaPriority:
replicaPriority, err := strconv.ParseUint(value, 10, 64)
replicaPriority, err := strconv.ParseInt(value, 10, 64)
if err != nil || replicaPriority < 0 {
invalid = true
} else {
config._replicaPriority = int64(replicaPriority)
config._replicaPriority = replicaPriority
}
}
@ -522,9 +521,3 @@ func (config *Config) setReadOnly(v bool) {
config._readOnly = v
config.mu.Unlock()
}
func (config *Config) logConfig() string {
config.mu.RLock()
v := config._logConfig
config.mu.RUnlock()
return v
}

View File

@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"
"time"
@ -272,7 +271,7 @@ func (s *Server) followStep(host string, port int, followc int) error {
s.mu.Unlock()
log.Info("caught up")
}
nullw := ioutil.Discard
nullw := io.Discard
for {
v, telnet, _, err := conn.rd.ReadMultiBulk()
if err != nil {

View File

@ -113,9 +113,7 @@ func (s *Server) cmdSetHook(msg *Message) (
cmsg := &Message{}
*cmsg = *msg
cmsg.Args = make([]string, len(commandvs))
for i := 0; i < len(commandvs); i++ {
cmsg.Args[i] = commandvs[i]
}
copy(cmsg.Args, commandvs)
metas := make([]FenceMeta, 0, len(metaMap))
for key, val := range metaMap {
metas = append(metas, FenceMeta{key, val})

View File

@ -7,6 +7,7 @@ import (
"github.com/tidwall/tile38/core"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
@ -65,9 +66,9 @@ func (s *Server) MetricsHandler(w http.ResponseWriter, r *http.Request) {
reg := prometheus.NewRegistry()
reg.MustRegister(
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
prometheus.NewGoCollector(),
prometheus.NewBuildInfoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
collectors.NewGoCollector(),
collectors.NewBuildInfoCollector(),
cmdDurations,
s,
)

View File

@ -19,7 +19,6 @@ func PO(x, y float64) *geojson.Point {
return geojson.NewPoint(geometry.Point{X: x, Y: y})
}
func BenchmarkFieldMatch(t *testing.B) {
rand.Seed(time.Now().UnixNano())
items := make([]testPointItem, t.N)

View File

@ -1,4 +1,4 @@
// +build !linux,!darwin
//go:build !linux && !darwin
package server

View File

@ -1,4 +1,4 @@
// +build linux darwin
//go:build linux || darwin
package server