Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3abb87d

Browse files
authored
chore: remove usage of ioutil (#642)
It was deprecated as of 1.17.
1 parent8c0f109 commit3abb87d

File tree

9 files changed

+28
-27
lines changed

9 files changed

+28
-27
lines changed

‎.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ linters-settings:
2727
-codegenComment
2828
# - commentedOutCode
2929
-commentedOutImport
30-
#- commentFormatting
30+
-commentFormatting
3131
-defaultCaseOrder
3232
-deferUnlambda
3333
# - deprecatedComment
@@ -54,7 +54,7 @@ linters-settings:
5454
# - importShadow
5555
-indexAlloc
5656
-initClause
57-
#- ioutilDeprecated
57+
-ioutilDeprecated
5858
-mapKey
5959
-methodExprCall
6060
# - nestingReduce

‎cli/config/file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package config
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"os"
66
"path/filepath"
77
)
@@ -67,5 +67,5 @@ func read(path string) ([]byte, error) {
6767
returnnil,err
6868
}
6969
deferfi.Close()
70-
returnioutil.ReadAll(fi)
70+
returnio.ReadAll(fi)
7171
}

‎cli/login.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package cli
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/url"
8+
"os"
89
"os/exec"
910
"os/user"
1011
"runtime"
@@ -30,8 +31,8 @@ func init() {
3031
// when in SSH or another type of headless session
3132
// NOTE: This needs to be in `init` to prevent data races
3233
// (multiple threads trying to set the global browser.Std* variables)
33-
browser.Stderr=ioutil.Discard
34-
browser.Stdout=ioutil.Discard
34+
browser.Stderr=io.Discard
35+
browser.Stdout=io.Discard
3536
}
3637

3738
funclogin()*cobra.Command {
@@ -205,7 +206,7 @@ func isWSL() (bool, error) {
205206
ifruntime.GOOS==goosDarwin||runtime.GOOS==goosWindows {
206207
returnfalse,nil
207208
}
208-
data,err:=ioutil.ReadFile("/proc/version")
209+
data,err:=os.ReadFile("/proc/version")
209210
iferr!=nil {
210211
returnfalse,xerrors.Errorf("read /proc/version: %w",err)
211212
}

‎cli/start.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"database/sql"
88
"encoding/pem"
99
"fmt"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"net/url"
@@ -383,10 +382,12 @@ func newProvisionerDaemon(ctx context.Context, client *codersdk.Client, logger s
383382
panic(err)
384383
}
385384
}()
386-
tempDir,err:=ioutil.TempDir("","provisionerd")
385+
386+
tempDir,err:=os.MkdirTemp("","provisionerd")
387387
iferr!=nil {
388388
returnnil,err
389389
}
390+
390391
returnprovisionerd.New(client.ListenProvisionerDaemon,&provisionerd.Options{
391392
Logger:logger,
392393
PollInterval:50*time.Millisecond,
@@ -473,7 +474,7 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
473474

474475
iftlsClientCAFile!="" {
475476
caPool:=x509.NewCertPool()
476-
data,err:=ioutil.ReadFile(tlsClientCAFile)
477+
data,err:=os.ReadFile(tlsClientCAFile)
477478
iferr!=nil {
478479
returnnil,xerrors.Errorf("read %q: %w",tlsClientCAFile,err)
479480
}

‎cmd/templater/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"net/http/httptest"
109
"net/url"
@@ -263,10 +262,12 @@ func newProvisionerDaemon(ctx context.Context, client *codersdk.Client, logger s
263262
panic(err)
264263
}
265264
}()
266-
tempDir,err:=ioutil.TempDir("","provisionerd")
265+
266+
tempDir,err:=os.MkdirTemp("","provisionerd")
267267
iferr!=nil {
268-
returnnil,err
268+
returnnil,xerrors.Errorf("mkdir temp: %w",err)
269269
}
270+
270271
returnprovisionerd.New(client.ListenProvisionerDaemon,&provisionerd.Options{
271272
Logger:logger,
272273
PollInterval:50*time.Millisecond,

‎coderd/coderdtest/coderdtest.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"encoding/json"
1414
"encoding/pem"
1515
"io"
16-
"io/ioutil"
1716
"math/big"
1817
"net"
1918
"net/http"
@@ -323,7 +322,7 @@ func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*
323322
require.NoError(t,err)
324323
return&http.Response{
325324
StatusCode:http.StatusOK,
326-
Body:ioutil.NopCloser(bytes.NewReader(data)),
325+
Body:io.NopCloser(bytes.NewReader(data)),
327326
Header:make(http.Header),
328327
},nil
329328
}),
@@ -334,7 +333,7 @@ func NewGoogleInstanceIdentity(t *testing.T, instanceID string, expired bool) (*
334333
Transport:roundTripper(func(r*http.Request) (*http.Response,error) {
335334
return&http.Response{
336335
StatusCode:http.StatusOK,
337-
Body:ioutil.NopCloser(bytes.NewReader([]byte(signedKey))),
336+
Body:io.NopCloser(bytes.NewReader([]byte(signedKey))),
338337
Header:make(http.Header),
339338
},nil
340339
}),
@@ -379,19 +378,19 @@ func NewAWSInstanceIdentity(t *testing.T, instanceID string) (awsidentity.Certif
379378
case"/latest/api/token":
380379
return&http.Response{
381380
StatusCode:http.StatusOK,
382-
Body:ioutil.NopCloser(bytes.NewReader([]byte("faketoken"))),
381+
Body:io.NopCloser(bytes.NewReader([]byte("faketoken"))),
383382
Header:make(http.Header),
384383
},nil
385384
case"/latest/dynamic/instance-identity/signature":
386385
return&http.Response{
387386
StatusCode:http.StatusOK,
388-
Body:ioutil.NopCloser(bytes.NewReader(signature)),
387+
Body:io.NopCloser(bytes.NewReader(signature)),
389388
Header:make(http.Header),
390389
},nil
391390
case"/latest/dynamic/instance-identity/document":
392391
return&http.Response{
393392
StatusCode:http.StatusOK,
394-
Body:ioutil.NopCloser(bytes.NewReader(document)),
393+
Body:io.NopCloser(bytes.NewReader(document)),
395394
Header:make(http.Header),
396395
},nil
397396
default:

‎coderd/database/dump/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"database/sql"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -81,7 +80,7 @@ func main() {
8180
if!ok {
8281
panic("couldn't get caller path")
8382
}
84-
err=ioutil.WriteFile(filepath.Join(mainPath,"..","..","dump.sql"), []byte(dump),0600)
83+
err=os.WriteFile(filepath.Join(mainPath,"..","..","dump.sql"), []byte(dump),0600)
8584
iferr!=nil {
8685
panic(err)
8786
}

‎coderd/database/postgres/postgres.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package postgres
33
import (
44
"database/sql"
55
"fmt"
6-
"io/ioutil"
76
"net"
87
"os"
98
"sync"
@@ -48,10 +47,12 @@ func Open() (string, func(), error) {
4847
iferr!=nil {
4948
return"",nil,xerrors.Errorf("create pool: %w",err)
5049
}
51-
tempDir,err:=ioutil.TempDir(os.TempDir(),"postgres")
50+
51+
tempDir,err:=os.MkdirTemp(os.TempDir(),"postgres")
5252
iferr!=nil {
5353
return"",nil,xerrors.Errorf("create tempdir: %w",err)
5454
}
55+
5556
openPortMutex.Lock()
5657
// Pick an explicit port on the host to connect to 5432.
5758
// This is necessary so we can configure the port to only use ipv4.

‎provisionersdk/archive_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package provisionersdk_test
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -14,7 +13,7 @@ import (
1413
funcTestTar(t*testing.T) {
1514
t.Parallel()
1615
dir:=t.TempDir()
17-
file,err:=ioutil.TempFile(dir,"")
16+
file,err:=os.CreateTemp(dir,"")
1817
require.NoError(t,err)
1918
_=file.Close()
2019
_,err=provisionersdk.Tar(dir)
@@ -24,7 +23,7 @@ func TestTar(t *testing.T) {
2423
funcTestUntar(t*testing.T) {
2524
t.Parallel()
2625
dir:=t.TempDir()
27-
file,err:=ioutil.TempFile(dir,"")
26+
file,err:=os.CreateTemp(dir,"")
2827
require.NoError(t,err)
2928
_=file.Close()
3029
archive,err:=provisionersdk.Tar(dir)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp