Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Mar 3, 2023
1 parent 392145d commit 30058b4
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -82,7 +81,7 @@ type Config struct {
// the directory, if such a file exists.
func (c *Config) FromDirectory(dir string) error {
path := filepath.Join(dir, "_config.yml")
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
switch {
case os.IsNotExist(err):
// break
Expand Down Expand Up @@ -224,7 +223,7 @@ func (c *Config) Map(key string) (map[string]interface{}, bool) {
return nil, false
}

//String returns the config indexed by key, if it's a string.
// String returns the config indexed by key, if it's a string.
func (c *Config) String(key string) (string, bool) {
if m, ok := c.m[key]; ok {
if m, ok := m.(string); ok {
Expand Down
4 changes: 2 additions & 2 deletions pages/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pages

import (
"bytes"
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -46,7 +46,7 @@ func TestPage_Write(t *testing.T) {

t.Run("rendering error", func(t *testing.T) {
p := requirePageFromFile(t, "liquid_error.md")
err := p.Write(ioutil.Discard)
err := p.Write(io.Discard)
require.NotNil(t, err)
require.Contains(t, err.Error(), "render error")
pe, ok := err.(utils.PathError)
Expand Down
3 changes: 1 addition & 2 deletions renderers/layouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package renderers

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -50,7 +49,7 @@ loop:
for _, dir := range p.layoutDirs() {
for _, ext := range exts {
filename = filepath.Join(dir, base+ext)
content, err = ioutil.ReadFile(filename)
content, err = os.ReadFile(filename)
if err == nil {
found = true
break loop
Expand Down
3 changes: 1 addition & 2 deletions renderers/sass.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/md5" // nolint: gas
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (p *Manager) copySASSFileIncludes() error {

func (p *Manager) makeSASSTempDir() error {
if p.sassTempDir == "" {
dir, err := ioutil.TempDir(os.TempDir(), "_sass")
dir, err := os.MkdirTemp(os.TempDir(), "_sass")
if p.cfg.Verbose {
fmt.Println("create", dir)
}
Expand Down
3 changes: 1 addition & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"html"
"io"
"io/ioutil"
"mime"
"net/http"
"os"
Expand Down Expand Up @@ -104,7 +103,7 @@ func fileErrorContext(e error) (s, path string) {
return
}
path, n := cause.Path(), cause.LineNumber()
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return
}
Expand Down
7 changes: 3 additions & 4 deletions site/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package site
import (
"encoding/csv"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -13,7 +12,7 @@ import (
func (s *Site) readDataFiles() error {
s.data = map[string]interface{}{}
dataDir := filepath.Join(s.SourceDir(), s.cfg.DataDir)
files, err := ioutil.ReadDir(dataDir)
files, err := os.ReadDir(dataDir)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand Down Expand Up @@ -50,15 +49,15 @@ func readDataFile(filename string) (interface{}, error) {
r := csv.NewReader(f)
return r.ReadAll()
case ".json":
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var d interface{}
err = json.Unmarshal(b, &d)
return d, err
case ".yaml", ".yml":
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions utils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"syscall"
Expand Down Expand Up @@ -55,7 +54,7 @@ func ReadFileMagic(filename string) ([]byte, error) {
// PostfixWalk is like filepath.Walk, but visits each directory after visiting its children instead of before.
// It does not implement SkipDir.
func PostfixWalk(root string, walkFn filepath.WalkFunc) error {
if files, err := ioutil.ReadDir(root); err == nil {
if files, err := os.ReadDir(root); err == nil {
for _, stat := range files {
if stat.IsDir() {
if err = PostfixWalk(filepath.Join(root, stat.Name()), walkFn); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions utils/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"

Expand All @@ -16,7 +16,7 @@ func testFile(name string) string {
}

func TestCopyFileContents(t *testing.T) {
f, err := ioutil.TempFile("", "ioutil-test")
f, err := os.CreateTemp("", "ioutil-test")
if err != nil {
t.Fatal(err)
}
Expand All @@ -25,7 +25,7 @@ func TestCopyFileContents(t *testing.T) {
err = CopyFileContents(f.Name(), testFile("test.txt"), 0x644)
require.NoError(t, err)

b, err := ioutil.ReadFile(f.Name())
b, err := os.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
Expand All @@ -49,7 +49,7 @@ func TestReadFileMagic(t *testing.T) {
}

func TestVisitCreatedFile(t *testing.T) {
f, err := ioutil.TempFile("", "ioutil-test")
f, err := os.CreateTemp("", "ioutil-test")
if err != nil {
t.Fatal(err)
}
Expand All @@ -61,7 +61,7 @@ func TestVisitCreatedFile(t *testing.T) {
})
require.NoError(t, err)

b, err := ioutil.ReadFile(f.Name())
b, err := os.ReadFile(f.Name())
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 30058b4

Please sign in to comment.