diff --git a/api.go b/api.go index 6a5833e..f08096a 100644 --- a/api.go +++ b/api.go @@ -3,7 +3,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -103,7 +102,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) { // Read sources.json file and return a list of SourceItem. func readSources() []MusicItem { - data, err := ioutil.ReadFile("./sources.json") + data, err := os.ReadFile("./sources.json") fmt.Println("[Info] Reading local sources.json") if err != nil { fmt.Println("[Error] Failed to read sources.json:", err) @@ -124,7 +123,7 @@ func readSources() []MusicItem { func getLocalMusicItem(song, singer string) MusicItem { musicDir := "./files/music" fmt.Println("[Info] Reading local folder music.") - files, err := ioutil.ReadDir(musicDir) + files, err := os.ReadDir(musicDir) if err != nil { fmt.Println("[Error] Failed to read local music directory:", err) return MusicItem{} diff --git a/files/.DS_Store b/files/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/files/.DS_Store differ diff --git a/files/background.webp b/files/background.webp new file mode 100644 index 0000000..6124d9d Binary files /dev/null and b/files/background.webp differ diff --git a/helper.go b/helper.go index f66517c..249c8fb 100644 --- a/helper.go +++ b/helper.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "mime" "net/http" "os" @@ -67,7 +66,7 @@ func createM3U8Playlist(outputDir string) error { } chunkDir := filepath.Join(outputDir, "chunk") - files, err := ioutil.ReadDir(chunkDir) + files, err := os.ReadDir(chunkDir) if err != nil { return err } @@ -223,7 +222,7 @@ func requestAndCacheMusic(song, singer string) { // If no valid music item was found, return an empty MusicItem if musicItem.Title == "" { - fmt.Println("[Warning] No valid music item retrieved.") + fmt.Printf("[Warning] No valid music item retrieved.\n") return } @@ -236,7 +235,7 @@ func requestAndCacheMusic(song, singer string) { fmt.Println("[Error] Error marshalling cache data:", err) return } - err = ioutil.WriteFile(cacheFile, cacheData, 0644) + err = os.WriteFile(cacheFile, cacheData, 0644) if err != nil { fmt.Println("[Error] Error writing cache file:", err) return @@ -247,7 +246,7 @@ func requestAndCacheMusic(song, singer string) { // Helper function to read music data from cache file func readFromCache(filePath string) (MusicItem, bool) { - data, err := ioutil.ReadFile(filePath) + data, err := os.ReadFile(filePath) if err != nil { fmt.Println("[Error] Failed to read cache file:", err) return MusicItem{}, false diff --git a/index.go b/index.go index 0227c13..3daed7c 100644 --- a/index.go +++ b/index.go @@ -3,6 +3,8 @@ package main import ( "fmt" "net/http" + "os" + "path/filepath" ) func indexHandler(w http.ResponseWriter, r *http.Request) { @@ -13,5 +15,361 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { fileHandler(w, r) return } - fmt.Fprintf(w, "