Use go 1.16 features (#292)
* Use features from Go 1.16 tooling. - GO111MODULE environment variable now defaults to "on" - "go build" and "go test" now exit with an error rather than silently modifying go.mod or go.sum files - Update README.md * Don't use deprecated ioutil package.
This commit is contained in:
parent
b97609cd2c
commit
83253f3c19
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@ -17,11 +17,7 @@ jobs:
|
|||||||
- name: Install Linters
|
- 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"
|
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
|
- name: Build
|
||||||
env:
|
|
||||||
GO111MODULE: "on"
|
|
||||||
run: go build ./...
|
run: go build ./...
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
|
||||||
GO111MODULE: "on"
|
|
||||||
run: |
|
run: |
|
||||||
./run_tests.sh
|
./run_tests.sh
|
||||||
|
|||||||
@ -42,7 +42,7 @@ VSP will add the ticket to a pool of always-online voting wallets.
|
|||||||
|
|
||||||
## Implementation
|
## Implementation
|
||||||
|
|
||||||
vspd is built and tested on go 1.15 and 1.16, making use of the following
|
vspd is built and tested on go 1.16 and 1.17, making use of the following
|
||||||
libraries:
|
libraries:
|
||||||
|
|
||||||
- [gin-gonic/gin](https://github.com/gin-gonic/gin) webserver.
|
- [gin-gonic/gin](https://github.com/gin-gonic/gin) webserver.
|
||||||
|
|||||||
@ -7,7 +7,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@ -325,7 +324,7 @@ func loadConfig() (*config, error) {
|
|||||||
|
|
||||||
// Load dcrd RPC certificate.
|
// Load dcrd RPC certificate.
|
||||||
cfg.DcrdCert = cleanAndExpandPath(cfg.DcrdCert)
|
cfg.DcrdCert = cleanAndExpandPath(cfg.DcrdCert)
|
||||||
cfg.dcrdCert, err = ioutil.ReadFile(cfg.DcrdCert)
|
cfg.dcrdCert, err = os.ReadFile(cfg.DcrdCert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read dcrd cert file: %w", err)
|
return nil, fmt.Errorf("failed to read dcrd cert file: %w", err)
|
||||||
}
|
}
|
||||||
@ -377,7 +376,7 @@ func loadConfig() (*config, error) {
|
|||||||
cfg.walletCerts = make([][]byte, numCert)
|
cfg.walletCerts = make([][]byte, numCert)
|
||||||
for i := 0; i < numCert; i++ {
|
for i := 0; i < numCert; i++ {
|
||||||
certs[i] = cleanAndExpandPath(certs[i])
|
certs[i] = cleanAndExpandPath(certs[i])
|
||||||
cfg.walletCerts[i], err = ioutil.ReadFile(certs[i])
|
cfg.walletCerts[i], err = os.ReadFile(certs[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read dcrwallet cert file: %w", err)
|
return nil, fmt.Errorf("failed to read dcrwallet cert file: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ package database
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
@ -152,7 +152,7 @@ func testHTTPBackup(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check reported length matches actual.
|
// Check reported length matches actual.
|
||||||
body, err := ioutil.ReadAll(rr.Result().Body)
|
body, err := io.ReadAll(rr.Result().Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not read http response body: %v", err)
|
t.Fatalf("could not read http response body: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
13
run_tests.sh
13
run_tests.sh
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Copyright (c) 2020 The Decred developers
|
# Copyright (c) 2020-2021 The Decred developers
|
||||||
# Use of this source code is governed by an ISC
|
# Use of this source code is governed by an ISC
|
||||||
# license that can be found in the LICENSE file.
|
# license that can be found in the LICENSE file.
|
||||||
#
|
#
|
||||||
@ -11,17 +11,6 @@ set -ex
|
|||||||
|
|
||||||
go version
|
go version
|
||||||
|
|
||||||
# run `go mod download` and `go mod tidy` and fail if the git status of
|
|
||||||
# go.mod and/or go.sum changes
|
|
||||||
MOD_STATUS=$(git status --porcelain go.mod go.sum)
|
|
||||||
go mod download
|
|
||||||
go mod tidy
|
|
||||||
UPDATED_MOD_STATUS=$(git status --porcelain go.mod go.sum)
|
|
||||||
if [ "$UPDATED_MOD_STATUS" != "$MOD_STATUS" ]; then
|
|
||||||
echo "Running `go mod tidy` modified go.mod and/or go.sum"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# run tests
|
# run tests
|
||||||
env GORACE="halt_on_error=1" go test -race ./...
|
env GORACE="halt_on_error=1" go test -race ./...
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ package webapi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -106,12 +106,12 @@ func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
|
|||||||
// drainAndReplaceBody will read and return the body of the provided request. It
|
// drainAndReplaceBody will read and return the body of the provided request. It
|
||||||
// replaces the request reader with an identical one so it can be used again.
|
// replaces the request reader with an identical one so it can be used again.
|
||||||
func drainAndReplaceBody(req *http.Request) ([]byte, error) {
|
func drainAndReplaceBody(req *http.Request) ([]byte, error) {
|
||||||
reqBytes, err := ioutil.ReadAll(req.Body)
|
reqBytes, err := io.ReadAll(req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Body.Close()
|
req.Body.Close()
|
||||||
req.Body = ioutil.NopCloser(bytes.NewBuffer(reqBytes))
|
req.Body = io.NopCloser(bytes.NewBuffer(reqBytes))
|
||||||
return reqBytes, nil
|
return reqBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package webapi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@ -70,7 +69,7 @@ func formattedStack() []byte {
|
|||||||
// Print this much at least. If we can't find the source, it won't show.
|
// Print this much at least. If we can't find the source, it won't show.
|
||||||
fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
|
fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
|
||||||
if file != lastFile {
|
if file != lastFile {
|
||||||
data, err := ioutil.ReadFile(file)
|
data, err := os.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user