コード例 #1
0
ファイル: submit.go プロジェクト: bieber/mixer
// Submit fires off a goroutine to actually mix the selected playlists
// into the destination list with the specified options.
func Submit(globalContext *context.GlobalContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		localContext := context.Get(r)

		userID, err := spotify.GetUserID(localContext.AuthTokens)
		if err != nil {
			panic(err)
		}

		data := submissionData{}
		err = json.NewDecoder(r.Body).Decode(&data)
		if err != nil {
			panic(err)
		}

		go mixPlaylists(globalContext, localContext, userID, data)
	}
}
コード例 #2
0
ファイル: playlists.go プロジェクト: bieber/mixer
// Playlists fetches and returns a list of the user's playlists as
// JSON.
func Playlists(w http.ResponseWriter, r *http.Request) {
	localContext := context.Get(r)

	userID, err := spotify.GetUserID(localContext.AuthTokens)
	if err != nil {
		panic(err)
	}
	playlists, err := spotify.GetPlaylists(localContext.AuthTokens, userID)
	if err != nil {
		panic(err)
	}

	result := map[string]interface{}{
		"userID":    userID,
		"playlists": playlists,
	}

	w.Header().Set("Content-type", "application/json")
	err = json.NewEncoder(w).Encode(result)
	if err != nil {
		panic(err)
	}
}