Commit 0b709e218f

0b709e218fc63499811ed9b0b6db3ae45ab3a1ef

parent: 02471056a4

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-19 21:13 UTC

Fix: io/ioutils is deprecated

Layout: unified · split

internal/anilist.go +6 −6
@@ -4,13 +4,13 @@ import (
44 "bytes"
55 "encoding/json"
66 "fmt"
7 "io/ioutil"
7 "io"
88 "net/http"
9 "os"
910 "strconv"
1011 "strings"
1112)
1213
13
1414// AniListAnime is the struct for the API response
1515type AniListAnime struct {
1616 ID int `json:"id"`
@@ -134,11 +134,11 @@ func SearchAnimeAnilist(query, token string) (map[string]string, error) {
134134 defer resp.Body.Close()
135135
136136 if resp.StatusCode != http.StatusOK {
137 body, _ := ioutil.ReadAll(resp.Body)
137 body, _ := io.ReadAll(resp.Body)
138138 return nil, fmt.Errorf("failed to search for anime. Status Code: %d, Response: %s", resp.StatusCode, string(body))
139139 }
140140
141 body, err := ioutil.ReadAll(resp.Body)
141 body, err := io.ReadAll(resp.Body)
142142 if err != nil {
143143 return nil, fmt.Errorf("failed to read response body: %w", err)
144144 }
@@ -315,7 +315,7 @@ func GetUserData(token string, userID int) (map[string]interface{}, error) {
315315
316316// Function to load a JSON file
317317func LoadJSONFile(filePath string) (map[string]interface{}, error) {
318 data, err := ioutil.ReadFile(filePath)
318 data, err := os.ReadFile(filePath)
319319 if err != nil {
320320 return nil, fmt.Errorf("failed to read file: %w", err)
321321 }
@@ -451,7 +451,7 @@ func makePostRequest(url, query string, variables map[string]interface{}, header
451451 }
452452 defer resp.Body.Close()
453453
454 body, err := ioutil.ReadAll(resp.Body)
454 body, err := io.ReadAll(resp.Body)
455455 if err != nil {
456456 return nil, fmt.Errorf("failed to read response body: %w", err)
457457 }
internal/anime_list.go +2 −2
@@ -3,7 +3,7 @@ package internal
33import (
44 "encoding/json"
55 "fmt"
6 "io/ioutil"
6 "io"
77 "net/http"
88 // "strings"
99)
@@ -71,7 +71,7 @@ func SearchAnime(query, mode string) (map[string]string, error) {
7171 }
7272 defer resp.Body.Close()
7373
74 body, err := ioutil.ReadAll(resp.Body)
74 body, err := io.ReadAll(resp.Body)
7575 if err != nil {
7676 fmt.Println("Error reading response body:", err)
7777 return animeList, err
internal/curd.go +1 −2
@@ -3,7 +3,6 @@ package internal
33import (
44 "encoding/json"
55 "fmt"
6 "io/ioutil"
76 "os"
87 "runtime"
98 "strings"
@@ -12,7 +11,7 @@ import (
1211
1312func GetTokenFromFile(filePath string) (string, error) {
1413 // Read the token from the file
15 data, err := ioutil.ReadFile(filePath)
14 data, err := os.ReadFile(filePath)
1615 if err != nil {
1716 return "", fmt.Errorf("failed to read token from file: %w", err)
1817 }
internal/episode_list.go +2 −2
@@ -3,7 +3,7 @@ package internal
33import (
44 "encoding/json"
55 "fmt"
6 "io/ioutil"
6 "io"
77 "net/http"
88 "sort"
99 "strconv"
@@ -62,7 +62,7 @@ func EpisodesList(showID, mode string) ([]string, error) {
6262 }
6363 defer resp.Body.Close()
6464
65 body, err := ioutil.ReadAll(resp.Body)
65 body, err := io.ReadAll(resp.Body)
6666 if err != nil {
6767 fmt.Println("Error reading response body:", err)
6868 return episodes, err
internal/episode_url.go +5 −5
@@ -3,7 +3,7 @@ package internal
33import (
44 "encoding/json"
55 "fmt"
6 "io/ioutil"
6 "io"
77 "net/http"
88 "net/url"
99 "regexp"
@@ -71,13 +71,13 @@ func extractLinks(provider_id string) map[string]interface{} {
7171 // Send the request
7272 resp, err := client.Do(req)
7373 if err != nil {
74 fmt.Println("Error sending request:", err)
74 Log(fmt.Sprint("Error sending request:", err), logFile)
7575 return videoData
7676 }
7777 defer resp.Body.Close()
7878
7979 // Read the response body
80 body, err := ioutil.ReadAll(resp.Body)
80 body, err := io.ReadAll(resp.Body)
8181 if err != nil {
8282 fmt.Println("Error reading response:", err)
8383 return videoData
@@ -140,7 +140,7 @@ func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) {
140140 }
141141 defer resp.Body.Close()
142142
143 body, err := ioutil.ReadAll(resp.Body)
143 body, err := io.ReadAll(resp.Body)
144144 if err != nil {
145145 return nil, err
146146 }
@@ -170,7 +170,7 @@ func GetEpisodeURL(config CurdConfig, id string, epNo int) ([]string, error) {
170170 }
171171 }
172172 } else {
173 fmt.Println("Links field is not of the expected type []interface{}")
173 Log("Links field is not of the expected type []interface{}", logFile)
174174 }
175175 }
176176 }