diff --git a/assignment2/language.go b/assignment2/language.go index 6d020c27bb65751488fb6d76acd89908a69b546b..2a8eec6bd765f513bc0fa6c01402b042133faef1 100644 --- a/assignment2/language.go +++ b/assignment2/language.go @@ -27,14 +27,34 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) { resp := DoRequest(Client, w, URL3) // request link - err := json.NewDecoder(resp.Body).Decode(&I) // decode to I - if err != nil { // check for error + PageTot, err := strconv.Atoi(resp.Header.Get("X-Total-Pages")) // gets count of total pages + if err != nil { // check for error http.Error(w, err.Error(), http.StatusBadRequest) return } + for i := 1; i <= PageTot; i++ { // loops true total pages + URL := URL3 + "&page=" + strconv.Itoa(i) // sets url to one page + + resp := DoRequest(Client, w, URL) + + var TempID []IDLang //creat temp for id + + err := json.NewDecoder(resp.Body).Decode(&TempID) // decode to I + if err != nil { // check for error + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + I = append(I, TempID...) // adds test to I + + } + for i := range I { // loops true length of I URL := URL1 + "/" + strconv.Itoa(I[i].ID) + "/languages" // creats url for languages with id + if auth != "false" { + URL = URL + "?private_token=" + auth // adds token to link + } resp = DoRequest(Client, w, URL) // request link @@ -57,6 +77,6 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) { http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good - json.NewEncoder(w).Encode(L) + json.NewEncoder(w).Encode(L) // encode L }