Skip to content

Commit e9dee28

Browse files
committed
Remove usages of the deprecated ioutil package
1 parent 8e4da31 commit e9dee28

File tree

9 files changed

+40
-38
lines changed

9 files changed

+40
-38
lines changed

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ jobs:
6969
shell: msys2 {0}
7070
run: |
7171
set MSYSTEM=MINGW64
72-
curl -LO https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
73-
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
72+
curl -LO https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
73+
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
7474
7575
- name: Install frontend dependencies
7676
run: npm install

cmd/delete.go

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

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"os"
88

@@ -60,7 +60,7 @@ func delete(cmd *cobra.Command, args []string) error {
6060

6161
if resp.StatusCode != 200 {
6262
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
63-
body, _ := ioutil.ReadAll(resp.Body)
63+
body, _ := io.ReadAll(resp.Body)
6464
fmt.Println(string(body))
6565
return fmt.Errorf("Tidbyt API returned status: %s", resp.Status)
6666
}

cmd/devices.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"os"
99

@@ -45,7 +45,7 @@ func devices(cmd *cobra.Command, args []string) {
4545

4646
if resp.StatusCode != 200 {
4747
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
48-
body, _ := ioutil.ReadAll(resp.Body)
48+
body, _ := io.ReadAll(resp.Body)
4949
fmt.Println(string(body))
5050
os.Exit(1)
5151
}

cmd/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"os"
99
"text/tabwriter"
@@ -66,7 +66,7 @@ func listInstallations(cmd *cobra.Command, args []string) error {
6666
return fmt.Errorf("listing installations from API: %w", err)
6767
}
6868

69-
body, _ := ioutil.ReadAll(resp.Body)
69+
body, _ := io.ReadAll(resp.Body)
7070
if resp.StatusCode != 200 {
7171
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
7272
fmt.Println(string(body))

cmd/push.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"encoding/base64"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"os"
1111

@@ -56,7 +56,7 @@ func push(cmd *cobra.Command, args []string) error {
5656
}
5757

5858
if background && len(installationID) == 0 {
59-
return fmt.Errorf("Background push won't do anything unless you also specify an installation ID")
59+
return fmt.Errorf("Background push won't do anything unless you also specify an installation ID")
6060
}
6161

6262
if apiToken == "" {
@@ -71,7 +71,7 @@ func push(cmd *cobra.Command, args []string) error {
7171
return fmt.Errorf("blank Tidbyt API token (use `pixlet login`, set $%s or pass with --api-token)", APITokenEnv)
7272
}
7373

74-
imageData, err := ioutil.ReadFile(image)
74+
imageData, err := os.ReadFile(image)
7575
if err != nil {
7676
return fmt.Errorf("failed to read file %s: %w", image, err)
7777
}
@@ -107,7 +107,7 @@ func push(cmd *cobra.Command, args []string) error {
107107

108108
if resp.StatusCode != 200 {
109109
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
110-
body, _ := ioutil.ReadAll(resp.Body)
110+
body, _ := io.ReadAll(resp.Body)
111111
fmt.Println(string(body))
112112
return fmt.Errorf("Tidbyt API returned status: %s", resp.Status)
113113
}

cmd/render.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package cmd
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"image"
8+
"io"
79
"io/fs"
8-
"io/ioutil"
10+
"log"
911
"os"
1012
"path/filepath"
1113
"strings"
1214
"time"
13-
"encoding/json"
14-
"log"
15+
1516
"github.com/spf13/cobra"
1617
"tidbyt.dev/pixlet/encode"
1718
"tidbyt.dev/pixlet/globals"
@@ -20,7 +21,7 @@ import (
2021
)
2122

2223
var (
23-
configJson string
24+
configJson string
2425
output string
2526
magnify int
2627
renderGif bool
@@ -32,7 +33,7 @@ var (
3233
)
3334

3435
func init() {
35-
RenderCmd.Flags().StringVarP(&configJson,"config","c","","Config file in json format")
36+
RenderCmd.Flags().StringVarP(&configJson, "config", "c", "", "Config file in json format")
3637
RenderCmd.Flags().StringVarP(&output, "output", "o", "", "Path for rendered image")
3738
RenderCmd.Flags().BoolVarP(&renderGif, "gif", "", false, "Generate GIF instead of WebP")
3839
RenderCmd.Flags().BoolVarP(&silenceOutput, "silent", "", false, "Silence print statements when rendering app")
@@ -127,20 +128,23 @@ func render(cmd *cobra.Command, args []string) error {
127128
// Open the JSON file.
128129
file, err := os.Open(configJson)
129130
if err != nil {
130-
return fmt.Errorf("file open error %v",err)
131+
return fmt.Errorf("file open error %v", err)
131132
}
132-
133+
133134
// Use the `json.Unmarshal()` function to unmarshal the JSON file into the map variable.
134-
fileData, err := ioutil.ReadAll(file)
135+
fileData, err := io.ReadAll(file)
136+
if err != nil {
137+
return fmt.Errorf("file read error %v", err)
138+
}
135139
err = json.Unmarshal(fileData, &config)
136140
if err != nil {
137-
return fmt.Errorf("somewthing wrong with json %v",configJson)
141+
return fmt.Errorf("something wrong with json %v", configJson)
138142
}
139-
140-
log.Printf("got json config of %v",config)
143+
144+
log.Printf("got json config of %v", config)
141145

142146
} else {
143-
147+
144148
for _, param := range args[1:] {
145149
split := strings.Split(param, "=")
146150
if len(split) < 2 {

render/gen/embedfonts.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"encoding/base64"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"strings"
98
"text/template"
@@ -29,9 +28,9 @@ var fontDataRaw = map[string]string{
2928
`
3029

3130
func main() {
32-
fontFileInfos, err := ioutil.ReadDir(FontDir)
31+
fontFileInfos, err := os.ReadDir(FontDir)
3332
if err != nil {
34-
fmt.Printf("ioutil.ReadDir(%s): %s\n", FontDir, err)
33+
fmt.Printf("os.ReadDir(%s): %s\n", FontDir, err)
3534
os.Exit(1)
3635
}
3736

@@ -44,9 +43,9 @@ func main() {
4443
name := strings.TrimSuffix(ffi.Name(), ".bdf")
4544
path := fmt.Sprintf("%s/%s", FontDir, ffi.Name())
4645

47-
content, err := ioutil.ReadFile(path)
46+
content, err := os.ReadFile(path)
4847
if err != nil {
49-
fmt.Printf("ioutil.Readfile(%s): %s\n", path, err)
48+
fmt.Printf("os.Readfile(%s): %s\n", path, err)
5049
os.Exit(1)
5150
}
5251

server/browser/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
)
1010

@@ -28,7 +28,7 @@ func (b *Browser) pushHandler(w http.ResponseWriter, r *http.Request) {
2828
)
2929

3030
var result map[string]interface{}
31-
bodyBytes, err := ioutil.ReadAll(r.Body)
31+
bodyBytes, err := io.ReadAll(r.Body)
3232
if err != nil {
3333
w.WriteHeader(500)
3434
fmt.Fprintln(w, err)
@@ -97,7 +97,7 @@ func (b *Browser) pushHandler(w http.ResponseWriter, r *http.Request) {
9797
w.WriteHeader(resp.StatusCode)
9898
fmt.Fprintln(w, err)
9999

100-
body, _ := ioutil.ReadAll(resp.Body)
100+
body, _ := io.ReadAll(resp.Body)
101101
fmt.Println(string(body))
102102
return
103103
}

server/loader/loader.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import (
99
"fmt"
1010
"io/fs"
1111
"log"
12+
"os"
1213
"time"
1314

1415
"tidbyt.dev/pixlet/encode"
1516
"tidbyt.dev/pixlet/runtime"
1617
"tidbyt.dev/pixlet/schema"
17-
18-
"io/ioutil"
1918
)
2019

2120
// Loader is a structure to provide applet loading when a file changes or on
@@ -32,8 +31,8 @@ type Loader struct {
3231
maxDuration int
3332
initialLoad chan bool
3433
timeout int
35-
renderGif bool
36-
configOutFile string
34+
renderGif bool
35+
configOutFile string
3736
}
3837

3938
type Update struct {
@@ -108,11 +107,11 @@ func (l *Loader) Run() error {
108107
if err != nil {
109108
panic(err)
110109
}
111-
110+
112111
if l.configOutFile != "" {
113112
// Write the byte slice to the file.
114113
//log.Printf("writing to %v",l.configOutFile)
115-
err = ioutil.WriteFile(l.configOutFile, byteSlice, 0644)
114+
err = os.WriteFile(l.configOutFile, byteSlice, 0644)
116115
if err != nil {
117116
panic(err)
118117
}

0 commit comments

Comments
 (0)