Skip to content

Commit 3f23ff5

Browse files
committed
Mostly get rid of ioutil
1 parent 33c8027 commit 3f23ff5

5 files changed

Lines changed: 11 additions & 14 deletions

File tree

dnscrypt-proxy/common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"encoding/binary"
66
"errors"
7-
"io/ioutil"
87
"net"
98
"os"
109
"strconv"
@@ -161,7 +160,7 @@ func ExtractHostAndPort(str string, defaultPort int) (host string, port int) {
161160
}
162161

163162
func ReadTextFile(filename string) (string, error) {
164-
bin, err := ioutil.ReadFile(filename)
163+
bin, err := os.ReadFile(filename)
165164
if err != nil {
166165
return "", err
167166
}

dnscrypt-proxy/local-doh.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/base64"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"net/http"
109
"strings"
@@ -36,7 +35,7 @@ func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *ht
3635
start := time.Now()
3736
if request.Method == "POST" &&
3837
request.Header.Get("Content-Type") == dataType {
39-
packet, err = ioutil.ReadAll(io.LimitReader(request.Body, int64(MaxDNSPacketSize)))
38+
packet, err = io.ReadAll(io.LimitReader(request.Body, int64(MaxDNSPacketSize)))
4039
if err != nil {
4140
dlog.Warnf("No body in a local DoH query")
4241
return

dnscrypt-proxy/sources.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
76
"math/rand"
87
"net/url"
98
"os"
@@ -54,10 +53,10 @@ var timeNow = time.Now
5453

5554
func (source *Source) fetchFromCache(now time.Time) (delay time.Duration, err error) {
5655
var bin, sig []byte
57-
if bin, err = ioutil.ReadFile(source.cacheFile); err != nil {
56+
if bin, err = os.ReadFile(source.cacheFile); err != nil {
5857
return
5958
}
60-
if sig, err = ioutil.ReadFile(source.cacheFile + ".minisig"); err != nil {
59+
if sig, err = os.ReadFile(source.cacheFile + ".minisig"); err != nil {
6160
return
6261
}
6362
if err = source.checkSignature(bin, sig); err != nil {

dnscrypt-proxy/sources_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type SourceTestExpect struct {
6969
}
7070

7171
func readFixture(t *testing.T, name string) []byte {
72-
bin, err := ioutil.ReadFile(filepath.Join("testdata", name))
72+
bin, err := os.ReadFile(filepath.Join("testdata", name))
7373
if err != nil {
7474
t.Fatalf("Unable to read test fixture %s: %v", name, err)
7575
}
@@ -86,7 +86,7 @@ func writeSourceCache(t *testing.T, e *SourceTestExpect) {
8686
if perms == 0 {
8787
perms = 0644
8888
}
89-
if err := ioutil.WriteFile(path, f.content, perms); err != nil {
89+
if err := os.WriteFile(path, f.content, perms); err != nil {
9090
t.Fatalf("Unable to write cache file %s: %v", path, err)
9191
}
9292
if err := acl.Chmod(path, perms); err != nil {
@@ -109,7 +109,7 @@ func checkSourceCache(c *check.C, e *SourceTestExpect) {
109109
for _, f := range e.cache {
110110
path := e.cachePath + f.suffix
111111
_ = acl.Chmod(path, 0644) // don't worry if this fails, reading it will catch the same problem
112-
got, err := ioutil.ReadFile(path)
112+
got, err := os.ReadFile(path)
113113
c.DeepEqual(got, f.content, "Unexpected content for cache file '%s', err %v", path, err)
114114
if f.suffix != "" {
115115
continue

dnscrypt-proxy/xtransport.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"encoding/hex"
1111
"errors"
1212
"io"
13-
"io/ioutil"
1413
"math/rand"
1514
"net"
1615
"net/http"
1716
"net/url"
17+
"os"
1818
"strconv"
1919
"strings"
2020
"sync"
@@ -179,7 +179,7 @@ func (xTransport *XTransport) rebuildTransport() {
179179
if certPool == nil {
180180
dlog.Fatalf("Additional CAs not supported on this platform: %v", certPoolErr)
181181
}
182-
additionalCaCert, err := ioutil.ReadFile(clientCreds.rootCA)
182+
additionalCaCert, err := os.ReadFile(clientCreds.rootCA)
183183
if err != nil {
184184
dlog.Fatal(err)
185185
}
@@ -470,7 +470,7 @@ func (xTransport *XTransport) Fetch(
470470
}
471471
if body != nil {
472472
req.ContentLength = int64(len(*body))
473-
req.Body = ioutil.NopCloser(bytes.NewReader(*body))
473+
req.Body = io.NopCloser(bytes.NewReader(*body))
474474
}
475475
start := time.Now()
476476
resp, err := client.Do(req)
@@ -528,7 +528,7 @@ func (xTransport *XTransport) Fetch(
528528
}
529529
}
530530
tls := resp.TLS
531-
bin, err := ioutil.ReadAll(io.LimitReader(resp.Body, MaxHTTPBodyLength))
531+
bin, err := io.ReadAll(io.LimitReader(resp.Body, MaxHTTPBodyLength))
532532
if err != nil {
533533
return nil, statusCode, tls, rtt, err
534534
}

0 commit comments

Comments
 (0)