package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "https://64.112.43.106:3000/search?keywords=%E9%9D%92%E8%8A%B1%E7%93%B7&limit=1"
resp, err := http.Post(url)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)
var result struct {
Code int `json:"code"`
Data struct {
Songs []struct {
Name string `json:"name"`
Album struct {
Name string `json:"name"`
} `json:"album"`
Artists []struct {
Name string `json:"name"`
} `json:"artists"`
} `json:"songs"`
} `json:"result"`
}
err = decoder.Decode(&result)
if err != nil {
fmt.Println(err)
return
}
song := result.Data.Songs[0]
fmt.Println(song.Name, song.Album.Name)
for _, artist := range song.Artists {
fmt.Println(artist.Name)
}
}