Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: Use go 1.16 features. #2722

Merged
merged 5 commits into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/go.yml
Expand Up @@ -17,11 +17,7 @@ jobs:
- name: Install Linters
run: "curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.0"
- name: Build
env:
GO111MODULE: "on"
run: go build ./...
- name: Test
env:
GO111MODULE: "on"
run: |
sh ./run_tests.sh
4 changes: 2 additions & 2 deletions Dockerfile
@@ -1,4 +1,4 @@
FROM golang:1.15
FROM golang:1.17

#
# NOTE: The RPC server listens on localhost by default.
Expand Down Expand Up @@ -34,7 +34,7 @@ FROM golang:1.15
WORKDIR /go/src/github.com/decred/dcrd
COPY . .

RUN env GO111MODULE=on go install . ./cmd/...
RUN go install . ./cmd/...
davecgh marked this conversation as resolved.
Show resolved Hide resolved

# mainnet
EXPOSE 9108 9109
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.alpine
@@ -1,5 +1,5 @@
# Build image
FROM golang:1.15
FROM golang:1.17

#
# NOTE: The RPC server listens on localhost by default.
Expand Down Expand Up @@ -35,7 +35,7 @@ FROM golang:1.15
WORKDIR /go/src/github.com/decred/dcrd
COPY . .

RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go install . ./cmd/...
RUN CGO_ENABLED=0 GOOS=linux go install . ./cmd/...

# Production image
FROM alpine:3.14.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -125,7 +125,7 @@ https://decred.org/downloads/

<details><summary><b>Install Dependencies</b></summary>

- **Go 1.14 or 1.15**
- **Go 1.16 or 1.17**

Installation instructions can be found here: https://golang.org/doc/install.
Ensure Go was installed properly and is a supported version:
Expand Down
5 changes: 2 additions & 3 deletions addrmgr/addrmanager_test.go
Expand Up @@ -8,7 +8,6 @@ package addrmgr
import (
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestAddAddressByIP(t *testing.T) {
},
}

dir, err := ioutil.TempDir("", "testaddressbyip")
dir, err := os.MkdirTemp("", "testaddressbyip")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -537,7 +536,7 @@ func TestNetAddressKey(t *testing.T) {
}

func TestCorruptPeersFile(t *testing.T) {
dir, err := ioutil.TempDir("", "testcorruptpeersfile")
dir, err := os.MkdirTemp("", "testcorruptpeersfile")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion addrmgr/go.mod
@@ -1,6 +1,6 @@
module github.com/decred/dcrd/addrmgr/v2

go 1.11
go 1.16

require (
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
Expand Down
3 changes: 1 addition & 2 deletions blockchain/common_test.go
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"io/ioutil"
"math"
mrand "math/rand"
"os"
Expand Down Expand Up @@ -78,7 +77,7 @@ func createTestDatabase(dbName string, dbType string, net wire.CurrencyNet) (dat
}
} else {
// Create the directory for the test database.
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
err := fmt.Errorf("unable to create test db path: %w",
err)
Expand Down
3 changes: 1 addition & 2 deletions blockchain/fullblocks_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -70,7 +69,7 @@ func createTestDatabase(dbName string, dbType string, net wire.CurrencyNet) (dat
}
} else {
// Create the directory for the test database.
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
err := fmt.Errorf("unable to create test db path: %w",
err)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/go.mod
@@ -1,6 +1,6 @@
module github.com/decred/dcrd/blockchain/v4

go 1.14
go 1.16

require (
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0-20210409183916-7f402345f0a6
Expand Down
4 changes: 0 additions & 4 deletions blockchain/go.sum
Expand Up @@ -29,13 +29,11 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down Expand Up @@ -81,9 +79,7 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
Expand Down
2 changes: 1 addition & 1 deletion blockchain/stake/go.mod
@@ -1,6 +1,6 @@
module github.com/decred/dcrd/blockchain/stake/v4

go 1.13
go 1.16

require (
github.com/decred/dcrd/chaincfg/chainhash v1.0.2
Expand Down
4 changes: 0 additions & 4 deletions blockchain/stake/go.sum
Expand Up @@ -31,13 +31,11 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down Expand Up @@ -83,9 +81,7 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
Expand Down
3 changes: 1 addition & 2 deletions blockchain/stake/internal/ticketdb/chainio_test.go
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"encoding/hex"
"errors"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -390,7 +389,7 @@ func TestTicketHashesDeserializingErrors(t *testing.T) {
func TestLiveDatabase(t *testing.T) {
// Create a new database to store the accepted stake node data into.
dbName := "ffldb_ticketdb_test"
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
t.Fatalf("unable to create test db path: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions blockchain/stake/tickets_test.go
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/gob"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -467,7 +466,7 @@ func TestTicketDBLongChain(t *testing.T) {
/*
// Create a new database to store the accepted stake node data into.
dbName := "ffldb_staketest"
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
t.Fatalf("unable to create test db path: %v", err)
}
Expand Down Expand Up @@ -686,7 +685,7 @@ func TestTicketDBGeneral(t *testing.T) {

// Create a new database to store the accepted stake node data into.
dbName := "ffldb_staketest"
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
t.Fatalf("unable to create test db path: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions blockchain/treasury_test.go
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -212,7 +211,7 @@ func TestTreasuryStateSerialization(t *testing.T) {
func TestTreasuryDatabase(t *testing.T) {
// Create a new database to store treasury state.
dbName := "ffldb_treasurydb_test"
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
t.Fatalf("unable to create treasury db path: %v", err)
}
Expand Down Expand Up @@ -294,7 +293,7 @@ func TestTreasuryDatabase(t *testing.T) {
func TestTSpendDatabase(t *testing.T) {
// Create a new database to store treasury state.
dbName := "ffldb_tspenddb_test"
dbPath, err := ioutil.TempDir("", dbName)
dbPath, err := os.MkdirTemp("", dbName)
if err != nil {
t.Fatalf("unable to create tspend db path: %v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions cert_test.go
Expand Up @@ -8,22 +8,21 @@ import (
"crypto/elliptic"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"os"
"testing"
)

// TestCertCreationWithHosts creates a certificate pair with extra hosts and
// ensures the extra hosts are present in the generated files.
func TestCertCreationWithHosts(t *testing.T) {
certFile, err := ioutil.TempFile("", "certfile")
certFile, err := os.CreateTemp("", "certfile")
if err != nil {
t.Fatalf("Unable to create temp certfile: %s", err)
}
certFile.Close()
defer os.Remove(certFile.Name())

keyFile, err := ioutil.TempFile("", "keyfile")
keyFile, err := os.CreateTemp("", "keyfile")
if err != nil {
t.Fatalf("Unable to create temp keyfile: %s", err)
}
Expand All @@ -36,7 +35,7 @@ func TestCertCreationWithHosts(t *testing.T) {
if err != nil {
t.Fatalf("Certificate was not created correctly: %s", err)
}
certBytes, err := ioutil.ReadFile(certFile.Name())
certBytes, err := os.ReadFile(certFile.Name())
if err != nil {
t.Fatalf("Unable to read the certfile: %s", err)
}
Expand All @@ -58,14 +57,14 @@ func TestCertCreationWithHosts(t *testing.T) {
// TestCertCreationWithOutHosts ensures the creating a certificate pair without
// any hosts works as intended.
func TestCertCreationWithOutHosts(t *testing.T) {
certFile, err := ioutil.TempFile("", "certfile")
certFile, err := os.CreateTemp("", "certfile")
if err != nil {
t.Fatalf("Unable to create temp certfile: %s", err)
}
certFile.Close()
defer os.Remove(certFile.Name())

keyFile, err := ioutil.TempFile("", "keyfile")
keyFile, err := os.CreateTemp("", "keyfile")
if err != nil {
t.Fatalf("Unable to create temp keyfile: %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/gencerts/gencerts.go
Expand Up @@ -18,7 +18,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -153,10 +152,10 @@ func main() {
fatalf("key file %q already exists\n", keyname)
}

if err = ioutil.WriteFile(certname, cert.PEMBlock, 0644); err != nil {
if err = os.WriteFile(certname, cert.PEMBlock, 0644); err != nil {
fatalf("cannot write cert: %v\n", err)
}
if err = ioutil.WriteFile(keyname, keyBlock, 0600); err != nil {
if err = os.WriteFile(keyname, keyBlock, 0600); err != nil {
os.Remove(certname)
fatalf("cannot write key: %v\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion dcrec/go.mod
@@ -1,3 +1,3 @@
module github.com/decred/dcrd/dcrec

go 1.11
go 1.16
4 changes: 2 additions & 2 deletions dcrec/secp256k1/loadprecomputed.go
Expand Up @@ -9,7 +9,7 @@ import (
"compress/zlib"
"encoding/base64"
"encoding/binary"
"io/ioutil"
"io"
"strings"
"sync"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ var s256BytePoints = func() func() *bytePointTable {
if err != nil {
panic(err)
}
serialized, err := ioutil.ReadAll(r)
davecgh marked this conversation as resolved.
Show resolved Hide resolved
serialized, err := io.ReadAll(r)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion dcrutil/go.mod
@@ -1,6 +1,6 @@
module github.com/decred/dcrd/dcrutil/v4

go 1.13
go 1.16

require (
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions dcrutil/txsort/txsort_test.go
Expand Up @@ -8,7 +8,7 @@ package txsort
import (
"bytes"
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -94,7 +94,7 @@ func TestSort(t *testing.T) {
for _, test := range tests {
// Load and deserialize the test transaction.
filePath := filepath.Join("testdata", test.hexFile)
txHexBytes, err := ioutil.ReadFile(filePath)
txHexBytes, err := os.ReadFile(filePath)
if err != nil {
t.Errorf("ReadFile (%s): failed to read test file: %v",
test.name, err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,6 +1,6 @@
module github.com/decred/dcrd

go 1.13
go 1.16

require (
github.com/davecgh/go-spew v1.1.1
Expand Down