Skip to content
Snippets Groups Projects
Commit 995d10f7 authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

Have set up limit for commits

parent 4ab3bdae
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package assignment2
import (
"encoding/json"
"fmt"
"log"
"net/http"
"sort"
"strconv"
......@@ -51,14 +52,19 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
resp := DoRequest(Client, w, APIURL)
json.NewDecoder(resp.Body).Decode(&I)
err := json.NewDecoder(resp.Body).Decode(&I)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
resp = DoRequest(Client, w, APIURL)
json.NewDecoder(resp.Body).Decode(&C.Repos)
erer := len(I)
fmt.Println("heree:", erer)
err = json.NewDecoder(resp.Body).Decode(&C.Repos)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
for i := range I {
URL := APIURL + "/" + strconv.Itoa(I[i].ID) + "/repository/commits"
......@@ -67,7 +73,11 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
var Temp []Temp
json.NewDecoder(resp.Body).Decode(&Temp)
err = json.NewDecoder(resp.Body).Decode(&Temp)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
C.Repos[i].Commits = len(Temp)
......@@ -77,7 +87,15 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
sort.Slice(C.Repos, func(i, j int) bool { return C.Repos[i].Commits > C.Repos[j].Commits })
//limit := QueryGet("limit", "5", r)
limit := QueryGet("limit", "5", r)
fmt.Println(limit)
TempInt, err := strconv.Atoi(limit)
if err != nil {
log.Fatal(err)
}
C.Repos = C.Repos[:TempInt]
http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good
......
......@@ -3,8 +3,8 @@ package assignment2
//************* Commits ******************
type IDS struct {
ID int `json:"id"`
Name string `json:"path_with_namespace"`
ID int `json:"id"`
}
type Temp struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment