本文整理匯總了Golang中github.com/jmoiron/jsonq.JsonQuery.Array方法的典型用法代碼示例。如果您正苦於以下問題:Golang JsonQuery.Array方法的具體用法?Golang JsonQuery.Array怎麽用?Golang JsonQuery.Array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/jmoiron/jsonq.JsonQuery
的用法示例。
在下文中一共展示了JsonQuery.Array方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewPlaylist
// NewPlaylist gathers the metadata for a YouTube playlist and returns it.
func (yt YouTube) NewPlaylist(user *gumble.User, id string) ([]Song, error) {
var apiResponse *jsonq.JsonQuery
var songArray []Song
var err error
// Retrieve title of playlist
url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", id, dj.conf.ServiceKeys.Youtube)
if apiResponse, err = PerformGetRequest(url); err != nil {
return nil, err
}
title, _ := apiResponse.String("items", "0", "snippet", "title")
playlist := &AudioPlaylist{
id: id,
title: title,
}
maxSongs := math.MaxInt32
if dj.conf.General.MaxSongPerPlaylist > 0 {
maxSongs = dj.conf.General.MaxSongPerPlaylist
}
pageToken := ""
for len(songArray) < maxSongs { //Iterate over the pages
// Retrieve items in this page of the playlist
url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s&pageToken=%s",
id, dj.conf.ServiceKeys.Youtube, pageToken)
if apiResponse, err = PerformGetRequest(url); err != nil {
return nil, err
}
songs, _ := apiResponse.Array("items")
for j := 0; j < len(songs) && len(songArray) < maxSongs; j++ {
index := strconv.Itoa(j)
videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId")
if song, err := yt.NewSong(user, videoID, "", playlist); err == nil {
songArray = append(songArray, song)
}
}
if pageToken, err = apiResponse.String("nextPageToken"); err != nil {
break
}
}
return songArray, nil
}