[#638] Update to Go 1.16

Changes:

  * replace `iotuil` elements with the ones from `os` package;
  * replace `os.Filemode` with `fs.FileMode`;
  * use `signal.NotifyContext` instead of `NewGracefulContext` (removed).

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-28 17:01:31 +03:00 committed by Leonard Lyubich
parent 61f48a2736
commit 56d4410913
30 changed files with 74 additions and 102 deletions

View file

@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
go: [ '1.14.x', '1.15.x', '1.16.x' ]
go: [ '1.16.x' ]
steps:
- name: Setup go
uses: actions/setup-go@v2

View file

@ -1,4 +1,4 @@
FROM golang:1.14-alpine as basebuilder
FROM golang:1.16-alpine as basebuilder
RUN apk add --update make bash
FROM basebuilder as builder

View file

@ -1,4 +1,4 @@
FROM golang:1.14-alpine as basebuilder
FROM golang:1.16-alpine as basebuilder
RUN apk add --update make bash
FROM basebuilder as builder

View file

@ -1,4 +1,4 @@
FROM golang:1.14-alpine as basebuilder
FROM golang:1.16-alpine as basebuilder
RUN apk add --update make bash
FROM basebuilder as builder

View file

@ -1,4 +1,4 @@
FROM golang:1.14-alpine as basebuilder
FROM golang:1.16-alpine as basebuilder
RUN apk add --update make bash
FROM basebuilder as builder

View file

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"strconv"
@ -339,7 +338,7 @@ var getContainerInfoCmd = &cobra.Command{
)
if containerPathFrom != "" {
data, err := ioutil.ReadFile(containerPathFrom)
data, err := os.ReadFile(containerPathFrom)
if err != nil {
cmd.PrintErrln(fmt.Errorf("can't read file: %w", err))
return
@ -398,7 +397,7 @@ var getContainerInfoCmd = &cobra.Command{
}
}
err = ioutil.WriteFile(containerPathTo, data, 0644)
err = os.WriteFile(containerPathTo, data, 0644)
if err != nil {
cmd.PrintErrln(fmt.Errorf("can't write container to file: %w", err))
return
@ -472,7 +471,7 @@ var getExtendedACLCmd = &cobra.Command{
cmd.Println("Signature:")
printJSONMarshaler(cmd, sig, "signature")
if err = ioutil.WriteFile(containerPathTo, data, 0644); err != nil {
if err = os.WriteFile(containerPathTo, data, 0644); err != nil {
cmd.PrintErrln(err)
}
},
@ -636,7 +635,7 @@ func getSessionToken(path string) (*session.Token, error) {
var tok *session.Token
if path != "" {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
@ -661,7 +660,7 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error)
if err == nil {
printVerbose("Reading placement policy from file: %s", policyString)
data, err := ioutil.ReadFile(policyString)
data, err := os.ReadFile(policyString)
if err != nil {
return nil, fmt.Errorf("can't read file with placement policy: %w", err)
}
@ -839,7 +838,7 @@ func parseEACL(eaclPath string) (*eacl.Table, error) {
printVerbose("Reading EACL from file: %s", eaclPath)
data, err := ioutil.ReadFile(eaclPath)
data, err := os.ReadFile(eaclPath)
if err != nil {
return nil, fmt.Errorf("can't read file with EACL: %w", err)
}

View file

@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path/filepath"
@ -638,7 +637,7 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) {
default:
return nil, fmt.Errorf("invalid field number: %d", len(words))
case 1:
data, err := ioutil.ReadFile(words[0])
data, err := os.ReadFile(words[0])
if err != nil {
return nil, err
}
@ -808,7 +807,7 @@ func saveAndPrintHeader(cmd *cobra.Command, obj *object.Object, filename string)
cmd.Println(string(bs))
return nil
}
err := ioutil.WriteFile(filename, bs, os.ModePerm)
err := os.WriteFile(filename, bs, os.ModePerm)
if err != nil {
return err
}
@ -906,7 +905,7 @@ func getBearerToken(cmd *cobra.Command, flagname string) (*token.BearerToken, er
return nil, nil
}
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("can't read bearer token file: %w", err)
}

View file

@ -5,7 +5,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -195,7 +194,7 @@ func getKey() (*ecdsa.PrivateKey, error) {
}
func getKeyFromFile(keyPath string) (*ecdsa.PrivateKey, error) {
data, err := ioutil.ReadFile(keyPath)
data, err := os.ReadFile(keyPath)
if err != nil {
return nil, fmt.Errorf("%w: %v", errInvalidKey, err)
}

View file

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"time"
@ -303,7 +302,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) {
return
}
err = ioutil.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0644)
if err != nil {
cmd.PrintErrln(fmt.Errorf("can't write signed bearer token to file: %w", err))
return
@ -349,7 +348,7 @@ func signSessionToken(cmd *cobra.Command, _ []string) {
return
}
err = ioutil.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0644)
if err != nil {
cmd.PrintErrln(fmt.Errorf("can't write signed session token to %s: %w", to, err))
return
@ -389,7 +388,7 @@ func convertEACLTable(cmd *cobra.Command, _ []string) {
return
}
err = ioutil.WriteFile(to, data, 0644)
err = os.WriteFile(to, data, 0644)
if err != nil {
cmd.PrintErrln(fmt.Errorf("can't write exteded ACL table to file: %w", err))
return
@ -486,7 +485,7 @@ func keyerGenerate(filename string, d *keyer.Dashboard) error {
}
if filename != "" {
return ioutil.WriteFile(filename, key, 0600)
return os.WriteFile(filename, key, 0600)
}
return nil
@ -502,7 +501,7 @@ func fileExists(filename string) bool {
}
func keyerParseFile(filename string, d *keyer.Dashboard) error {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("can't open %v file: %w", filename, err)
}

View file

@ -1,16 +1,18 @@
package main
import (
"context"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-node/misc"
"github.com/nspcc-dev/neofs-node/pkg/innerring"
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
httputil "github.com/nspcc-dev/neofs-node/pkg/util/http"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -58,7 +60,9 @@ func main() {
log, err := logger.NewLogger(logPrm)
exitErr(err)
ctx := grace.NewGracefulContext(log)
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
defer cancel()
intErr := make(chan error) // internal inner ring errors
httpServers := initHTTPServers(cfg)

View file

@ -1,7 +1,7 @@
package engineconfig_test
import (
"os"
"io/fs"
"testing"
"time"
@ -47,7 +47,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 555, wc.WorkersNumber())
require.Equal(t, "tmp/0/meta", meta.Path())
require.Equal(t, os.FileMode(0700), meta.Perm())
require.Equal(t, fs.FileMode(0700), meta.Perm())
require.Equal(t, "tmp/0/blob", blob.Path())
require.EqualValues(t, 0666, blob.Perm())
@ -73,7 +73,7 @@ func TestEngineSection(t *testing.T) {
require.EqualValues(t, 556, wc.WorkersNumber())
require.Equal(t, "tmp/1/meta", meta.Path())
require.Equal(t, os.FileMode(0701), meta.Perm())
require.Equal(t, fs.FileMode(0701), meta.Perm())
require.Equal(t, "tmp/1/blob", blob.Path())
require.EqualValues(t, 0667, blob.Perm())

View file

@ -1,7 +1,7 @@
package blobstorconfig
import (
"os"
"io/fs"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
blobovniczaconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/blobstor/blobovnicza"
@ -45,10 +45,10 @@ func (x *Config) Path() string {
return p
}
// Perm returns value of "perm" config parameter as a os.FileMode.
// Perm returns value of "perm" config parameter as a fs.FileMode.
//
// Returns PermDefault if value is not a non-zero number.
func (x *Config) Perm() os.FileMode {
func (x *Config) Perm() fs.FileMode {
p := config.UintSafe(
(*config.Config)(x),
"perm",
@ -58,7 +58,7 @@ func (x *Config) Perm() os.FileMode {
p = PermDefault
}
return os.FileMode(p)
return fs.FileMode(p)
}
// ShallowDepth returns value of "shallow_depth" config parameter.

View file

@ -1,7 +1,7 @@
package metabaseconfig
import (
"os"
"io/fs"
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
)
@ -37,10 +37,10 @@ func (x *Config) Path() string {
return p
}
// Perm returns value of "perm" config parameter as a os.FileMode.
// Perm returns value of "perm" config parameter as a fs.FileMode.
//
// Returns PermDefault if value is not a positive number.
func (x *Config) Perm() os.FileMode {
func (x *Config) Perm() fs.FileMode {
p := config.UintSafe(
(*config.Config)(x),
"perm",
@ -50,5 +50,5 @@ func (x *Config) Perm() os.FileMode {
p = PermDefault
}
return os.FileMode(p)
return fs.FileMode(p)
}

View file

@ -3,7 +3,7 @@ package nodeconfig
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
@ -35,7 +35,7 @@ func Key(c *config.Config) *keys.PrivateKey {
err error
data []byte
)
if data, err = ioutil.ReadFile(v); err == nil {
if data, err = os.ReadFile(v); err == nil {
key, err = keys.NewPrivateKeyFromBytes(data)
}

View file

@ -5,10 +5,11 @@ import (
"flag"
"fmt"
"log"
"os/signal"
"syscall"
"github.com/nspcc-dev/neofs-node/misc"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
"go.uber.org/zap"
)
@ -48,7 +49,7 @@ func main() {
}
func initApp(c *cfg) {
c.ctx, c.ctxCancel = context.WithCancel(grace.NewGracefulContext(nil))
c.ctx, c.ctxCancel = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
initGRPC(c)

2
go.mod
View file

@ -1,6 +1,6 @@
module github.com/nspcc-dev/neofs-node
go 1.14
go 1.16
require (
github.com/golang/protobuf v1.5.2

BIN
go.sum

Binary file not shown.

View file

@ -1,6 +1,7 @@
package blobovnicza
import (
"io/fs"
"os"
"time"
@ -33,7 +34,7 @@ type cfg struct {
}
type boltDBCfg struct {
perm os.FileMode
perm fs.FileMode
path string
@ -77,7 +78,7 @@ func WithPath(path string) Option {
// WithPermissions returns option to specify permission bits
// of Blobovnicza's system path.
func WithPermissions(perm os.FileMode) Option {
func WithPermissions(perm fs.FileMode) Option {
return func(c *cfg) {
c.perm = perm
}

View file

@ -2,7 +2,7 @@ package blobstor
import (
"encoding/hex"
"os"
"io/fs"
"path"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
@ -145,7 +145,7 @@ func WithRootPath(rootDir string) Option {
// WithRootPerm returns option to set permission
// bits of the fs tree.
func WithRootPerm(perm os.FileMode) Option {
func WithRootPerm(perm fs.FileMode) Option {
return func(c *cfg) {
c.fsTree.Permissions = perm
c.blzOpts = append(c.blzOpts, blobovnicza.WithPermissions(perm))

View file

@ -3,7 +3,7 @@ package fstree
import (
"crypto/sha256"
"errors"
"io/ioutil"
"io/fs"
"os"
"path"
"strings"
@ -23,7 +23,7 @@ type FSTree struct {
// Info groups the information about file storage.
type Info struct {
// Permission bits of the root directory.
Permissions os.FileMode
Permissions fs.FileMode
// Full path to the root directory.
RootPath string
@ -73,7 +73,7 @@ func (t *FSTree) Iterate(f func(addr *objectSDK.Address, data []byte) error) err
func (t *FSTree) iterate(depth int, curPath []string, f func(*objectSDK.Address, []byte) error) error {
curName := strings.Join(curPath[1:], "")
des, err := ioutil.ReadDir(path.Join(curPath...))
des, err := os.ReadDir(path.Join(curPath...))
if err != nil {
return err
}
@ -101,7 +101,7 @@ func (t *FSTree) iterate(depth int, curPath []string, f func(*objectSDK.Address,
continue
}
data, err := ioutil.ReadFile(path.Join(curPath...))
data, err := os.ReadFile(path.Join(curPath...))
if err != nil {
return err
}
@ -161,7 +161,7 @@ func (t *FSTree) Put(addr *objectSDK.Address, data []byte) error {
return err
}
return ioutil.WriteFile(p, data, t.Permissions)
return os.WriteFile(p, data, t.Permissions)
}
// Get returns object from storage by address.
@ -172,5 +172,5 @@ func (t *FSTree) Get(addr *objectSDK.Address) ([]byte, error) {
return nil, ErrFileNotFound
}
return ioutil.ReadFile(p)
return os.ReadFile(p)
}

View file

@ -3,6 +3,7 @@ package meta
import (
"encoding/binary"
"encoding/hex"
"io/fs"
"os"
"strconv"
@ -132,7 +133,7 @@ func WithPath(path string) Option {
// WithPermissions returns option to specify permission bits
// of Metabase system path.
func WithPermissions(perm os.FileMode) Option {
func WithPermissions(perm fs.FileMode) Option {
return func(c *cfg) {
c.info.Permission = perm
}

View file

@ -1,7 +1,7 @@
package meta
import (
"os"
"io/fs"
)
// Info groups the information about DB.
@ -10,7 +10,7 @@ type Info struct {
Path string
// Permission of database file.
Permission os.FileMode
Permission fs.FileMode
}
// DumpInfo returns information about the DB.

View file

@ -1,32 +0,0 @@
package grace
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"go.uber.org/zap"
)
// NewGracefulContext returns grace context that cancelled by sigint,
// sigterm and sighup.
func NewGracefulContext(l *zap.Logger) context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
sig := <-ch
if l != nil {
l.Info("received signal",
zap.String("signal", sig.String()))
} else {
fmt.Printf("received signal %s\n", sig)
}
cancel()
}()
return ctx
}

View file

@ -2,7 +2,7 @@ package airportsdb
import (
"fmt"
"os"
"io/fs"
"sync"
)
@ -41,7 +41,7 @@ type DB struct {
type pathMode struct {
path string
mode os.FileMode
mode fs.FileMode
}
const invalidPrmValFmt = "invalid parameter %s (%T):%v"

View file

@ -1,19 +1,19 @@
package airportsdb
import (
"os"
"io/fs"
)
// Option sets an optional parameter of DB.
type Option func(*options)
type options struct {
airportMode, countryMode os.FileMode
airportMode, countryMode fs.FileMode
}
func defaultOpts() *options {
return &options{
airportMode: os.ModePerm, // 0777
countryMode: os.ModePerm, // 0777
airportMode: fs.ModePerm, // 0777
countryMode: fs.ModePerm, // 0777
}
}

View file

@ -2,7 +2,7 @@ package locodebolt
import (
"fmt"
"os"
"io/fs"
"go.etcd.io/bbolt"
)
@ -34,7 +34,7 @@ type Prm struct {
type DB struct {
path string
mode os.FileMode
mode fs.FileMode
boltOpts *bbolt.Options

View file

@ -1,6 +1,7 @@
package locodebolt
import (
"io/fs"
"os"
"time"
@ -11,7 +12,7 @@ import (
type Option func(*options)
type options struct {
mode os.FileMode
mode fs.FileMode
boltOpts *bbolt.Options
}

View file

@ -2,7 +2,7 @@ package continentsdb
import (
"fmt"
"io/ioutil"
"os"
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
"github.com/paulmach/orb"
@ -53,7 +53,7 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
}
func (db *DB) init() error {
data, err := ioutil.ReadFile(db.path)
data, err := os.ReadFile(db.path)
if err != nil {
return fmt.Errorf("could not read data file: %w", err)
}

View file

@ -1,14 +1,14 @@
package csvlocode
import (
"os"
"io/fs"
)
// Option sets an optional parameter of Table.
type Option func(*options)
type options struct {
mode os.FileMode
mode fs.FileMode
extraPaths []string
}

View file

@ -2,7 +2,7 @@ package csvlocode
import (
"fmt"
"os"
"io/fs"
"sync"
)
@ -32,7 +32,7 @@ type Prm struct {
type Table struct {
paths []string
mode os.FileMode
mode fs.FileMode
subDivPath string