update(spotify/json): check if json is ok with status and not json structure

This commit is contained in:
rick 2021-08-28 23:46:45 +02:00
parent 89e4644430
commit 757d55e125
Signed by: Rick
GPG key ID: 2B593F087240EE99
2 changed files with 7 additions and 153 deletions

153
server.go
View file

@ -4,130 +4,13 @@ import (
// "bytes" // "bytes"
"fmt" "fmt"
"log" "log"
"time" // "time"
"net/http" "net/http"
"encoding/json" "encoding/json"
) )
var MyClient = &http.Client{} var MyClient = &http.Client{}
type YoutubeAPI struct {
Href string `json:"href"`
Items []struct {
AddedAt time.Time `json:"added_at"`
AddedBy struct {
ExternalUrls struct {
Spotify string `json:"spotify"`
} `json:"external_urls"`
Href string `json:"href"`
ID string `json:"id"`
Type string `json:"type"`
URI string `json:"uri"`
} `json:"added_by"`
IsLocal bool `json:"is_local"`
PrimaryColor interface{} `json:"primary_color"`
Track struct {
Album struct {
AlbumType string `json:"album_type"`
Artists []struct {
ExternalUrls struct {
Spotify string `json:"spotify"`
} `json:"external_urls"`
Href string `json:"href"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
URI string `json:"uri"`
} `json:"artists"`
AvailableMarkets []string `json:"available_markets"`
ExternalUrls struct {
Spotify string `json:"spotify"`
} `json:"external_urls"`
Href string `json:"href"`
ID string `json:"id"`
Images []struct {
Height int `json:"height"`
URL string `json:"url"`
Width int `json:"width"`
} `json:"images"`
Name string `json:"name"`
ReleaseDate string `json:"release_date"`
ReleaseDatePrecision string `json:"release_date_precision"`
TotalTracks int `json:"total_tracks"`
Type string `json:"type"`
URI string `json:"uri"`
} `json:"album"`
Artists []struct {
ExternalUrls struct {
Spotify string `json:"spotify"`
} `json:"external_urls"`
Href string `json:"href"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
URI string `json:"uri"`
} `json:"artists"`
AvailableMarkets []string `json:"available_markets"`
DiscNumber int `json:"disc_number"`
DurationMs int `json:"duration_ms"`
Episode bool `json:"episode"`
Explicit bool `json:"explicit"`
ExternalIds struct {
Isrc string `json:"isrc"`
} `json:"external_ids"`
ExternalUrls struct {
Spotify string `json:"spotify"`
} `json:"external_urls"`
Href string `json:"href"`
ID string `json:"id"`
IsLocal bool `json:"is_local"`
Name string `json:"name"`
Popularity int `json:"popularity"`
PreviewURL string `json:"preview_url"`
Track bool `json:"track"`
TrackNumber int `json:"track_number"`
Type string `json:"type"`
URI string `json:"uri"`
} `json:"track"`
VideoThumbnail struct {
URL interface{} `json:"url"`
} `json:"video_thumbnail"`
} `json:"items"`
Limit int `json:"limit"`
Next string `json:"next"`
Offset int `json:"offset"`
Previous interface{} `json:"previous"`
Total int `json:"total"`
}
type Test struct {
Tee string
}
type ErrorSpotify struct {
href string
}
type Error struct {
status, message string
}
/* /*
id de la playlist id de la playlist
*/ */
@ -142,43 +25,21 @@ func getListPlaylist(id string) {
fmt.Printf("error:", err) fmt.Printf("error:", err)
return return
} }
fmt.Printf("hm", res.Status)
/*
buf := new(bytes.Buffer)
buf.ReadFrom(res.Body)
fmt.Printf("coucou %+v", buf.String()) if res.StatusCode > 300 {
*/ fmt.Printf("Erreur !!\n")
return
}
//ree := &ErrorSpotify{} ree := &SpotifyPlaylist{}
var ree YoutubeAPI defer res.Body.Close()
//defer res.Body.Close()
//json.Unmarshal(res.Body, ree)
err = json.NewDecoder(res.Body).Decode(&ree) err = json.NewDecoder(res.Body).Decode(&ree)
if err != nil { if err != nil {
fmt.Printf("error:", err) fmt.Printf("error:", err)
return return
} }
//json.NewDecoder(res.Body).Decode(interface{}(ree))
//decoder := json.NewDecoder(res.Body).Decode(interface{}(ree))
/*
for token, _ := decoder.Token(); token != nil; token, _ = decoder.Token() {
fmt.Printf("value:", token)
}
*/
//decoder.Decode(interface{}(ree))
fmt.Printf(ree.Href) fmt.Printf(ree.Href)
fmt.Printf("coucou\n")
return
token := map[string]string{}
fmt.Printf("coucou\n")
for _, v := range token {
fmt.Printf("coucou")
fmt.Printf("\n", v)
}
} }
func formHandler(w http.ResponseWriter, r *http.Request) { func formHandler(w http.ResponseWriter, r *http.Request) {

View file

@ -2,13 +2,6 @@ package main
import "time" import "time"
type SpotyfyError struct {
Error struct {
Status int `json:"status"`
Message string `json:"message"`
} `json:"error"`
}
type SpotifyPlaylist struct { type SpotifyPlaylist struct {
Href string `json:"href"` Href string `json:"href"`
Items []struct { Items []struct {