當前位置: 首頁>>代碼示例>>Golang>>正文


Golang JsonQuery.ArrayOfObjects方法代碼示例

本文整理匯總了Golang中github.com/jmoiron/jsonq.JsonQuery.ArrayOfObjects方法的典型用法代碼示例。如果您正苦於以下問題:Golang JsonQuery.ArrayOfObjects方法的具體用法?Golang JsonQuery.ArrayOfObjects怎麽用?Golang JsonQuery.ArrayOfObjects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jmoiron/jsonq.JsonQuery的用法示例。


在下文中一共展示了JsonQuery.ArrayOfObjects方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRequest

// NewRequest creates the requested song/playlist and adds to the queue
func (sc SoundCloud) NewRequest(user *gumble.User, url string) ([]Song, error) {
	var apiResponse *jsonq.JsonQuery
	var songArray []Song
	var err error
	timesplit := strings.Split(url, "#t=")
	url = fmt.Sprintf("http://api.soundcloud.com/resolve?url=%s&client_id=%s", timesplit[0], dj.conf.ServiceKeys.SoundCloud)
	if apiResponse, err = PerformGetRequest(url); err != nil {
		return nil, errors.New(fmt.Sprintf(INVALID_API_KEY, sc.ServiceName()))
	}

	tracks, err := apiResponse.ArrayOfObjects("tracks")
	if err == nil {
		// PLAYLIST
		// Create playlist
		title, _ := apiResponse.String("title")
		permalink, _ := apiResponse.String("permalink_url")
		playlist := &AudioPlaylist{
			id:    permalink,
			title: title,
		}

		if dj.conf.General.MaxSongPerPlaylist > 0 && len(tracks) > dj.conf.General.MaxSongPerPlaylist {
			tracks = tracks[:dj.conf.General.MaxSongPerPlaylist]
		}
		// Add all tracks
		for _, t := range tracks {
			if song, err := sc.NewSong(user, jsonq.NewQuery(t), 0, playlist); err == nil {
				songArray = append(songArray, song)
			}
		}
		return songArray, nil
	} else {
		// SONG
		// Calculate offset
		offset := 0
		if len(timesplit) == 2 {
			timesplit = strings.Split(timesplit[1], ":")
			multiplier := 1
			for i := len(timesplit) - 1; i >= 0; i-- {
				time, _ := strconv.Atoi(timesplit[i])
				offset += time * multiplier
				multiplier *= 60
			}
		}

		// Add the track
		if song, err := sc.NewSong(user, apiResponse, offset, nil); err == nil {
			return append(songArray, song), err
		}
		return nil, err
	}
}
開發者ID:hpincket,項目名稱:mumbledjkhaled,代碼行數:53,代碼來源:service_soundcloud.go


注:本文中的github.com/jmoiron/jsonq.JsonQuery.ArrayOfObjects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。