Skip to content

Commit

Permalink
Remove usages of the deprecated ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
IngmarStein committed Feb 10, 2025
1 parent 8e4da31 commit e9dee28
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ jobs:
shell: msys2 {0}
run: |
set MSYSTEM=MINGW64
curl -LO https://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.2.4-4-any.pkg.tar.zst
curl -LO https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
pacman -U --noconfirm mingw-w64-x86_64-libwebp-1.5.0-1-any.pkg.tar.zst
- name: Install frontend dependencies
run: npm install
Expand Down
4 changes: 2 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

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

if resp.StatusCode != 200 {
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
return fmt.Errorf("Tidbyt API returned status: %s", resp.Status)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

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

if resp.StatusCode != 200 {
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"text/tabwriter"
Expand Down Expand Up @@ -66,7 +66,7 @@ func listInstallations(cmd *cobra.Command, args []string) error {
return fmt.Errorf("listing installations from API: %w", err)
}

body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != 200 {
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
fmt.Println(string(body))
Expand Down
8 changes: 4 additions & 4 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

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

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

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

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

if resp.StatusCode != 200 {
fmt.Printf("Tidbyt API returned status %s\n", resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
return fmt.Errorf("Tidbyt API returned status: %s", resp.Status)
}
Expand Down
28 changes: 16 additions & 12 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"image"
"io"
"io/fs"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"time"
"encoding/json"
"log"

"github.com/spf13/cobra"
"tidbyt.dev/pixlet/encode"
"tidbyt.dev/pixlet/globals"
Expand All @@ -20,7 +21,7 @@ import (
)

var (
configJson string
configJson string
output string
magnify int
renderGif bool
Expand All @@ -32,7 +33,7 @@ var (
)

func init() {
RenderCmd.Flags().StringVarP(&configJson,"config","c","","Config file in json format")
RenderCmd.Flags().StringVarP(&configJson, "config", "c", "", "Config file in json format")
RenderCmd.Flags().StringVarP(&output, "output", "o", "", "Path for rendered image")
RenderCmd.Flags().BoolVarP(&renderGif, "gif", "", false, "Generate GIF instead of WebP")
RenderCmd.Flags().BoolVarP(&silenceOutput, "silent", "", false, "Silence print statements when rendering app")
Expand Down Expand Up @@ -127,20 +128,23 @@ func render(cmd *cobra.Command, args []string) error {
// Open the JSON file.
file, err := os.Open(configJson)
if err != nil {
return fmt.Errorf("file open error %v",err)
return fmt.Errorf("file open error %v", err)
}

// Use the `json.Unmarshal()` function to unmarshal the JSON file into the map variable.
fileData, err := ioutil.ReadAll(file)
fileData, err := io.ReadAll(file)
if err != nil {
return fmt.Errorf("file read error %v", err)
}
err = json.Unmarshal(fileData, &config)
if err != nil {
return fmt.Errorf("somewthing wrong with json %v",configJson)
return fmt.Errorf("something wrong with json %v", configJson)
}
log.Printf("got json config of %v",config)

log.Printf("got json config of %v", config)

} else {

for _, param := range args[1:] {
split := strings.Split(param, "=")
if len(split) < 2 {
Expand Down
9 changes: 4 additions & 5 deletions render/gen/embedfonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"strings"
"text/template"
Expand All @@ -29,9 +28,9 @@ var fontDataRaw = map[string]string{
`

func main() {
fontFileInfos, err := ioutil.ReadDir(FontDir)
fontFileInfos, err := os.ReadDir(FontDir)
if err != nil {
fmt.Printf("ioutil.ReadDir(%s): %s\n", FontDir, err)
fmt.Printf("os.ReadDir(%s): %s\n", FontDir, err)
os.Exit(1)
}

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

content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
fmt.Printf("ioutil.Readfile(%s): %s\n", path, err)
fmt.Printf("os.Readfile(%s): %s\n", path, err)
os.Exit(1)
}

Expand Down
6 changes: 3 additions & 3 deletions server/browser/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
)

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

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

body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
return
}
Expand Down
11 changes: 5 additions & 6 deletions server/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"fmt"
"io/fs"
"log"
"os"
"time"

"tidbyt.dev/pixlet/encode"
"tidbyt.dev/pixlet/runtime"
"tidbyt.dev/pixlet/schema"

"io/ioutil"
)

// Loader is a structure to provide applet loading when a file changes or on
Expand All @@ -32,8 +31,8 @@ type Loader struct {
maxDuration int
initialLoad chan bool
timeout int
renderGif bool
configOutFile string
renderGif bool
configOutFile string
}

type Update struct {
Expand Down Expand Up @@ -108,11 +107,11 @@ func (l *Loader) Run() error {
if err != nil {
panic(err)
}

if l.configOutFile != "" {
// Write the byte slice to the file.
//log.Printf("writing to %v",l.configOutFile)
err = ioutil.WriteFile(l.configOutFile, byteSlice, 0644)
err = os.WriteFile(l.configOutFile, byteSlice, 0644)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit e9dee28

Please sign in to comment.