Skip to content

Commit 0344a9a

Browse files
committed
remove deprecated ioutil
1 parent 3ec5b26 commit 0344a9a

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

cmd/docsite/serve.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package main
33
import (
44
"crypto/tls"
55
"flag"
6-
"io/ioutil"
76
"log"
87
"net"
98
"net/http"
9+
"os"
1010
"sync"
1111
)
1212

@@ -49,11 +49,11 @@ func init() {
4949
}
5050
if *tlsCertPath != "" || *tlsKeyPath != "" {
5151
log.Printf("# TLS listener enabled")
52-
tlsCert, err := ioutil.ReadFile(*tlsCertPath)
52+
tlsCert, err := os.ReadFile(*tlsCertPath)
5353
if err != nil {
5454
return err
5555
}
56-
tlsKey, err := ioutil.ReadFile(*tlsKeyPath)
56+
tlsKey, err := os.ReadFile(*tlsKeyPath)
5757
if err != nil {
5858
return err
5959
}

cmd/docsite/site.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"log"
1111
"net/http"
1212
"net/url"
@@ -36,7 +36,7 @@ func siteFromFlags() (*docsite.Site, *docsiteConfig, error) {
3636

3737
paths := filepath.SplitList(*configPath)
3838
for _, path := range paths {
39-
data, err := ioutil.ReadFile(path)
39+
data, err := os.ReadFile(path)
4040
if os.IsNotExist(err) {
4141
continue
4242
} else if err != nil {
@@ -324,7 +324,7 @@ func (fs *versionedFileSystemURL) fetchAndCacheVersion(version string) (http.Fil
324324
if strings.Contains(urlStr, "$VERSION") && strings.Contains(urlStr, "github") && !strings.Contains(urlStr, "refs/heads/$VERSION") {
325325
return nil, fmt.Errorf("refusing to use insecure docsite configuration for multi-version-aware GitHub URLs: the URL pattern %q must include \"refs/heads/$VERSION\", not just \"$VERSION\" (see docsite README.md for more information)", urlStr)
326326
}
327-
urlStr = strings.Replace(fs.url, "$VERSION", version, -1)
327+
urlStr = strings.ReplaceAll(fs.url, "$VERSION", version)
328328

329329
// HACK: Workaround for https://github.com/sourcegraph/sourcegraph-public-snapshot/issues/3030. This assumes
330330
// that tags all begin with "vN" where N is some number.
@@ -363,7 +363,7 @@ func zipFileSystemAtURL(url, dir string) (http.FileSystem, error) {
363363
} else if resp.StatusCode != http.StatusOK {
364364
return nil, &os.PathError{Op: "Get", Path: url, Err: fmt.Errorf("HTTP response status code %d", resp.StatusCode)}
365365
}
366-
body, err := ioutil.ReadAll(resp.Body)
366+
body, err := io.ReadAll(resp.Body)
367367
if err != nil {
368368
return nil, err
369369
}
@@ -397,7 +397,7 @@ func mapFromZipArchive(z *zip.Reader, dir string) (map[string]string, error) {
397397
if err != nil {
398398
return nil, errors.WithMessagef(err, "open %q", zf.Name)
399399
}
400-
data, err := ioutil.ReadAll(f)
400+
data, err := io.ReadAll(f)
401401
f.Close()
402402
if err != nil {
403403
return nil, errors.WithMessagef(err, "read %q", zf.Name)

template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"context"
66
"fmt"
77
"html/template"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"net/url"
1111
"os"
@@ -42,7 +42,7 @@ func (s *Site) getTemplate(templatesFS http.FileSystem, name string, extraFuncs
4242
return nil, err
4343
}
4444
defer f.Close()
45-
data, err := ioutil.ReadAll(f)
45+
data, err := io.ReadAll(f)
4646
if err != nil {
4747
return nil, err
4848
}

util.go

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

33
import (
4-
"io/ioutil"
4+
"io"
55
"net/http"
66
)
77

@@ -11,5 +11,5 @@ func ReadFile(fs http.FileSystem, path string) ([]byte, error) {
1111
return nil, err
1212
}
1313
defer f.Close()
14-
return ioutil.ReadAll(f)
14+
return io.ReadAll(f)
1515
}

0 commit comments

Comments
 (0)