Compare commits

..
1 Commits
Author SHA1 Message Date
sulzlep ab65e1dcf0 no idea 2024-11-26 21:36:25 +01:00
2 changed files with 51 additions and 0 deletions
View File
+51
View File
@@ -0,0 +1,51 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Response struct {
Title string `json:"title"`
Artist string `json:"artist"`
Album string `json:"album"`
Year string `json:"year"`
Time int `json:"time"` // Seconds to go to end of song
Cover string `json:"cover"` // URL to picture of album cover
}
/*func getImage(url string) {
fmt.Println("Calling API and get image...")
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Print(err.Error())
}
return req
}
*/
func main() {
fmt.Println("Calling API...")
client := &http.Client{}
req, err := http.NewRequest("GET", "https://api.radioparadise.com/api/now_playing", nil)
if err != nil {
fmt.Print(err.Error())
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Print(err.Error())
}
var responseObject Response
json.Unmarshal(bodyBytes, &responseObject)
// coverUrl := responseObject.Cover
// getImage(coverUrl)
fmt.Printf("API Response as struct %+v\n", responseObject)
fmt.Println("Image from albumcover...")
}