Skip to content

Commit

Permalink
get rid of ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
KappaDistributive committed May 12, 2024
1 parent f7a9cbf commit 47ea8f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
7 changes: 3 additions & 4 deletions v1/lesson.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -22,7 +21,7 @@ func createSampleLessons() {
errorHandling(err)
}

files, err := ioutil.ReadDir(home + "/.config/gotypist/lessons")
files, err := os.ReadDir(home + "/.config/gotypist/lessons")
if err != nil {
errorHandling(err)
}
Expand All @@ -49,7 +48,7 @@ func createSampleLessons() {
}

func createLessonFromBagOfWords(home string) error {
files, err := ioutil.ReadDir("data/bags_of_words")
files, err := os.ReadDir("data/bags_of_words")
if err != nil {
return err
}
Expand All @@ -65,7 +64,7 @@ func createLessonFromBagOfWords(home string) error {
}

func createLessonsFromSampleLessons(home string) error{
files, err := ioutil.ReadDir("data/sample_lessons")
files, err := os.ReadDir("data/sample_lessons")
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions v1/lesson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
Expand All @@ -18,7 +17,7 @@ func Test_copyLesson_ShouldNotReturnErrorWhenAbleToCreateLesson(t *testing.T) {
err := copyLesson(sourceFilePath, targetFilePath)

assert.NoError(t, err)
files, err := ioutil.ReadDir(targetDirectory)
files, err := os.ReadDir(targetDirectory)
assert.NoError(t, err)
assert.Len(t, files, 1)
assert.Contains(t, files[0].Name(), targetFile)
Expand All @@ -45,4 +44,4 @@ func setupSource(t *testing.T) func(){
err := os.RemoveAll("./tmp")
assert.NoError(t, err)
}
}
}
9 changes: 3 additions & 6 deletions v1/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package main

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"
"time"

ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
Expand Down Expand Up @@ -64,7 +62,7 @@ func createSelection(cursorPos int) Selection {
lessons := []Lesson{}

// Create top 300 words lesson
data, err := ioutil.ReadFile(home + BagsOfWordsDir + "/en_us.yaml")
data, err := os.ReadFile(home + BagsOfWordsDir + "/en_us.yaml")
if err != nil {
errorHandling(err)
}
Expand All @@ -76,7 +74,6 @@ func createSelection(cursorPos int) Selection {
lesson_length := 0
var index int
var new_word string
rand.Seed(time.Now().UnixNano())
for lesson_length < BagsOfWordsLessonLengthInCharacters {
index = rand.Intn(299)
new_word = bagOfWords.Words[index]
Expand All @@ -100,12 +97,12 @@ func createSelection(cursorPos int) Selection {
content.Rows = append(content.Rows, lesson.Title)

// Load lessons from directory
files, err := ioutil.ReadDir(home + LessonsDir)
files, err := os.ReadDir(home + LessonsDir)
if err != nil {
errorHandling(err)
}
for _, fileinfo := range files {
data, err := ioutil.ReadFile(home + LessonsDir + "/" + fileinfo.Name())
data, err := os.ReadFile(home + LessonsDir + "/" + fileinfo.Name())
if err != nil {
errorHandling(err)
}
Expand Down

0 comments on commit 47ea8f7

Please sign in to comment.