From 11843ff8675d589183d791f350ab20b075834263 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Fri, 20 Aug 2021 23:18:21 +0300 Subject: [PATCH] go: upgrade to 1.17 --- .github/workflows/ci.yml | 8 +++++++- cmd/entc/entc.go | 6 +++--- cmd/internal/base/base.go | 5 ++--- dialect/gremlin/http.go | 3 +-- dialect/gremlin/http_test.go | 3 +-- entc/gen/feature.go | 3 +-- entc/gen/graph.go | 11 +++++------ entc/integration/hooks/ent/internal/schema.go | 1 + entc/integration/privacy/ent/internal/schema.go | 1 + entc/internal/snapshot.go | 4 ++-- entc/internal/snapshot_test.go | 3 +-- entc/internal/vcs_test.go | 5 ++--- entc/load/load.go | 3 +-- entc/tools.go | 1 + entql/internal/gen.go | 6 +++--- examples/entcpkg/ent/entc.go | 1 + examples/privacyadmin/ent/internal/schema.go | 1 + examples/privacytenant/ent/internal/schema.go | 1 + examples/version/ent/internal/schema.go | 1 + go.mod | 16 +++++++++++++++- schema/field/internal/gen.go | 6 +++--- 21 files changed, 54 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ead622e87..73d91293f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: ['1.16', '1.15'] + go: ['1.17', '1.16'] steps: - uses: actions/checkout@v2.3.4 - uses: actions/setup-go@v2 @@ -56,6 +56,8 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - uses: actions/setup-go@v2 + with: + go-version: '1.17' - uses: actions/cache@v2.1.6 with: path: ~/go/pkg/mod @@ -214,6 +216,8 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - uses: actions/setup-go@v2 + with: + go-version: '1.17' - uses: actions/cache@v2.1.6 with: path: ~/go/pkg/mod @@ -368,6 +372,8 @@ jobs: with: fetch-depth: 0 - uses: actions/setup-go@v2 + with: + go-version: '1.17' - uses: actions/cache@v2.1.6 with: path: ~/go/pkg/mod diff --git a/cmd/entc/entc.go b/cmd/entc/entc.go index c50fe927e..434ac8f4e 100644 --- a/cmd/entc/entc.go +++ b/cmd/entc/entc.go @@ -6,8 +6,8 @@ package main import ( "bytes" - "io/ioutil" "log" + "os" "path/filepath" "entgo.io/ent/cmd/internal/base" @@ -32,9 +32,9 @@ func migrate(c *gen.Config) { target = filepath.Join(c.Target, "generate.go") oldCmd = []byte("entgo.io/ent/cmd/entc") ) - buf, err := ioutil.ReadFile(target) + buf, err := os.ReadFile(target) if err != nil || !bytes.Contains(buf, oldCmd) { return } - _ = ioutil.WriteFile(target, bytes.ReplaceAll(buf, oldCmd, []byte("entgo.io/ent/cmd/ent")), 0644) + _ = os.WriteFile(target, bytes.ReplaceAll(buf, oldCmd, []byte("entgo.io/ent/cmd/ent")), 0644) } diff --git a/cmd/internal/base/base.go b/cmd/internal/base/base.go index 44020b009..a12f0130d 100644 --- a/cmd/internal/base/base.go +++ b/cmd/internal/base/base.go @@ -9,7 +9,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -190,7 +189,7 @@ func initEnv(target string, names []string) error { return fmt.Errorf("executing template %s: %w", name, err) } newFileTarget := filepath.Join(target, strings.ToLower(name+".go")) - if err := ioutil.WriteFile(newFileTarget, b.Bytes(), 0644); err != nil { + if err := os.WriteFile(newFileTarget, b.Bytes(), 0644); err != nil { return fmt.Errorf("writing file %s: %w", newFileTarget, err) } } @@ -208,7 +207,7 @@ func createDir(target string) error { if target != defaultSchema { return nil } - if err := ioutil.WriteFile("ent/generate.go", []byte(genFile), 0644); err != nil { + if err := os.WriteFile("ent/generate.go", []byte(genFile), 0644); err != nil { return fmt.Errorf("creating generate.go file: %w", err) } return nil diff --git a/dialect/gremlin/http.go b/dialect/gremlin/http.go index 6b664231b..351c406d8 100644 --- a/dialect/gremlin/http.go +++ b/dialect/gremlin/http.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/url" @@ -69,7 +68,7 @@ func (t *httpTransport) RoundTrip(ctx context.Context, req *Request) (*Response, defer rsp.Body.Close() if rsp.StatusCode < http.StatusOK || rsp.StatusCode > http.StatusPartialContent { - body, _ := ioutil.ReadAll(rsp.Body) + body, _ := io.ReadAll(rsp.Body) return nil, fmt.Errorf("gremlin/http: status=%q, body=%q", rsp.Status, body) } if rsp.ContentLength > MaxResponseSize { diff --git a/dialect/gremlin/http_test.go b/dialect/gremlin/http_test.go index a6c86626d..9669142b4 100644 --- a/dialect/gremlin/http_test.go +++ b/dialect/gremlin/http_test.go @@ -7,7 +7,6 @@ package gremlin import ( "context" "io" - "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -22,7 +21,7 @@ import ( func TestHTTPTransportRoundTripper(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, r.Header.Get("Content-Type"), "application/json") - got, err := ioutil.ReadAll(r.Body) + got, err := io.ReadAll(r.Body) require.NoError(t, err) assert.JSONEq(t, `{"gremlin": "g.V(1)", "language": "gremlin-groovy"}`, string(got)) diff --git a/entc/gen/feature.go b/entc/gen/feature.go index ca68f6040..bf0f6a057 100644 --- a/entc/gen/feature.go +++ b/entc/gen/feature.go @@ -5,7 +5,6 @@ package gen import ( - "io/ioutil" "os" "path/filepath" ) @@ -164,7 +163,7 @@ func remove(dir, file string) error { } return err } - infos, err := ioutil.ReadDir(dir) + infos, err := os.ReadDir(dir) if err != nil { return err } diff --git a/entc/gen/graph.go b/entc/gen/graph.go index 226eff122..9abe662ba 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -11,7 +11,6 @@ import ( "fmt" "go/parser" "go/token" - "io/ioutil" "os" "path/filepath" "runtime/debug" @@ -693,7 +692,7 @@ func PrepareEnv(c *Config) (undo func() error, err error) { nop = func() error { return nil } path = filepath.Join(c.Target, "runtime.go") ) - out, err := ioutil.ReadFile(path) + out, err := os.ReadFile(path) if err != nil { if os.IsNotExist(err) { return nop, nil @@ -708,10 +707,10 @@ func PrepareEnv(c *Config) (undo func() error, err error) { if len(fi.Imports) == 0 { return nop, nil } - if err := ioutil.WriteFile(path, append([]byte("// +build tools\n"), out...), 0644); err != nil { + if err := os.WriteFile(path, append([]byte("// +build tools\n"), out...), 0644); err != nil { return nil, err } - return func() error { return ioutil.WriteFile(path, out, 0644) }, nil + return func() error { return os.WriteFile(path, out, 0644) }, nil } type ( @@ -733,7 +732,7 @@ func (a assets) write() error { } } for _, file := range a.files { - if err := ioutil.WriteFile(file.path, file.content, 0644); err != nil { + if err := os.WriteFile(file.path, file.content, 0644); err != nil { return fmt.Errorf("write file %q: %w", file.path, err) } } @@ -748,7 +747,7 @@ func (a assets) format() error { if err != nil { return fmt.Errorf("format file %s: %w", path, err) } - if err := ioutil.WriteFile(path, src, 0644); err != nil { + if err := os.WriteFile(path, src, 0644); err != nil { return fmt.Errorf("write file %s: %w", path, err) } } diff --git a/entc/integration/hooks/ent/internal/schema.go b/entc/integration/hooks/ent/internal/schema.go index b7834cdd4..af11b6b0c 100644 --- a/entc/integration/hooks/ent/internal/schema.go +++ b/entc/integration/hooks/ent/internal/schema.go @@ -4,6 +4,7 @@ // Code generated by entc, DO NOT EDIT. +//go:build tools // +build tools // Package internal holds a loadable version of the latest schema. diff --git a/entc/integration/privacy/ent/internal/schema.go b/entc/integration/privacy/ent/internal/schema.go index 51f055275..78456d179 100644 --- a/entc/integration/privacy/ent/internal/schema.go +++ b/entc/integration/privacy/ent/internal/schema.go @@ -4,6 +4,7 @@ // Code generated by entc, DO NOT EDIT. +//go:build tools // +build tools // Package internal holds a loadable version of the latest schema. diff --git a/entc/internal/snapshot.go b/entc/internal/snapshot.go index 54ccf2630..bb7197800 100644 --- a/entc/internal/snapshot.go +++ b/entc/internal/snapshot.go @@ -8,7 +8,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "entgo.io/ent/entc/gen" @@ -25,7 +25,7 @@ type Snapshot struct { // If there is a conflict between upstream and local snapshots, it is merged // before running the code generation. func (s *Snapshot) Restore() error { - buf, err := ioutil.ReadFile(s.Path) + buf, err := os.ReadFile(s.Path) if err != nil { return fmt.Errorf("unable to read snapshot schema %w", err) } diff --git a/entc/internal/snapshot_test.go b/entc/internal/snapshot_test.go index ec41bc340..fc67d1156 100644 --- a/entc/internal/snapshot_test.go +++ b/entc/internal/snapshot_test.go @@ -5,7 +5,6 @@ package internal import ( - "io/ioutil" "math/rand" "os" "os/exec" @@ -47,7 +46,7 @@ func TestSnapshot_Restore(t *testing.T) { // addConflicts adds VCS conflicts to the files that match the given patterns. func addConflicts(dir string) error { rand.Seed(time.Now().UnixNano()) - infos, err := ioutil.ReadDir(dir) + infos, err := os.ReadDir(dir) if err != nil { return err } diff --git a/entc/internal/vcs_test.go b/entc/internal/vcs_test.go index 8d12a5276..3a11528a8 100644 --- a/entc/internal/vcs_test.go +++ b/entc/internal/vcs_test.go @@ -6,7 +6,6 @@ package internal import ( "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -18,9 +17,9 @@ func TestCheckDir(t *testing.T) { target := filepath.Join(os.TempDir(), "entvcs") require.NoError(t, os.MkdirAll(target, os.ModePerm), "creating tmpdir") defer os.RemoveAll(target) - err := ioutil.WriteFile(filepath.Join(target, "a.go"), []byte(`package schema`), 0644) + err := os.WriteFile(filepath.Join(target, "a.go"), []byte(`package schema`), 0644) require.NoError(t, err) - err = ioutil.WriteFile(filepath.Join(target, "b.go"), []byte(`package schema + err = os.WriteFile(filepath.Join(target, "b.go"), []byte(`package schema type User struct { <<<<<<< local diff --git a/entc/load/load.go b/entc/load/load.go index b6fbd8fca..f957aff0b 100644 --- a/entc/load/load.go +++ b/entc/load/load.go @@ -13,7 +13,6 @@ import ( "go/parser" "go/token" "go/types" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -71,7 +70,7 @@ func (c *Config) Load() (*SchemaSpec, error) { return nil, err } target := fmt.Sprintf(".entc/%s.go", filename(pkgPath)) - if err := ioutil.WriteFile(target, buf, 0644); err != nil { + if err := os.WriteFile(target, buf, 0644); err != nil { return nil, fmt.Errorf("entc/load: write file %s: %w", target, err) } defer os.RemoveAll(".entc") diff --git a/entc/tools.go b/entc/tools.go index c2f70b008..f818ba82e 100644 --- a/entc/tools.go +++ b/entc/tools.go @@ -2,6 +2,7 @@ // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. +//go:build tools // +build tools package main diff --git a/entql/internal/gen.go b/entql/internal/gen.go index 4e131ce9e..97ffdf8de 100644 --- a/entql/internal/gen.go +++ b/entql/internal/gen.go @@ -8,8 +8,8 @@ package main import ( "bytes" "go/format" - "io/ioutil" "log" + "os" "strings" "text/template" @@ -17,7 +17,7 @@ import ( ) func main() { - buf, err := ioutil.ReadFile("internal/types.tmpl") + buf, err := os.ReadFile("internal/types.tmpl") if err != nil { log.Fatal("reading template file:", err) } @@ -59,7 +59,7 @@ func main() { if buf, err = format.Source(b.Bytes()); err != nil { log.Fatal("formatting output:", err) } - if err := ioutil.WriteFile("types.go", buf, 0644); err != nil { + if err := os.WriteFile("types.go", buf, 0644); err != nil { log.Fatal("writing go file:", err) } } diff --git a/examples/entcpkg/ent/entc.go b/examples/entcpkg/ent/entc.go index f5871e549..1cb899e4a 100644 --- a/examples/entcpkg/ent/entc.go +++ b/examples/entcpkg/ent/entc.go @@ -2,6 +2,7 @@ // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. +//go:build ignore // +build ignore package main diff --git a/examples/privacyadmin/ent/internal/schema.go b/examples/privacyadmin/ent/internal/schema.go index c4a5f99fd..77299924f 100644 --- a/examples/privacyadmin/ent/internal/schema.go +++ b/examples/privacyadmin/ent/internal/schema.go @@ -4,6 +4,7 @@ // Code generated by entc, DO NOT EDIT. +//go:build tools // +build tools // Package internal holds a loadable version of the latest schema. diff --git a/examples/privacytenant/ent/internal/schema.go b/examples/privacytenant/ent/internal/schema.go index 9587ac331..d24b7f6e3 100644 --- a/examples/privacytenant/ent/internal/schema.go +++ b/examples/privacytenant/ent/internal/schema.go @@ -4,6 +4,7 @@ // Code generated by entc, DO NOT EDIT. +//go:build tools // +build tools // Package internal holds a loadable version of the latest schema. diff --git a/examples/version/ent/internal/schema.go b/examples/version/ent/internal/schema.go index e84b0e9a1..12bb17e66 100644 --- a/examples/version/ent/internal/schema.go +++ b/examples/version/ent/internal/schema.go @@ -4,6 +4,7 @@ // Code generated by entc, DO NOT EDIT. +//go:build tools // +build tools // Package internal holds a loadable version of the latest schema. diff --git a/go.mod b/go.mod index 092ac0a5e..cab62a9ff 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module entgo.io/ent -go 1.16 +go 1.17 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 @@ -23,3 +23,17 @@ require ( golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/tools v0.1.5 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/mod v0.4.2 // indirect + golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/schema/field/internal/gen.go b/schema/field/internal/gen.go index 097b8e54a..073e6f8c4 100644 --- a/schema/field/internal/gen.go +++ b/schema/field/internal/gen.go @@ -8,8 +8,8 @@ package main import ( "bytes" "go/format" - "io/ioutil" "log" + "os" "strings" "text/template" @@ -17,7 +17,7 @@ import ( ) func main() { - buf, err := ioutil.ReadFile("internal/numeric.tmpl") + buf, err := os.ReadFile("internal/numeric.tmpl") if err != nil { log.Fatal("reading template file:", err) } @@ -50,7 +50,7 @@ func main() { if buf, err = format.Source(b.Bytes()); err != nil { log.Fatal("formatting output:", err) } - if err := ioutil.WriteFile("numeric.go", buf, 0644); err != nil { + if err := os.WriteFile("numeric.go", buf, 0644); err != nil { log.Fatal("writing go file:", err) } }