diff --git a/assignment2/language.go b/assignment2/language.go index 2a8eec6bd765f513bc0fa6c01402b042133faef1..8c838a72ecc6fb414ef7dc9b976f0e1ec680b4a8 100644 --- a/assignment2/language.go +++ b/assignment2/language.go @@ -2,15 +2,31 @@ package assignment2 import ( "encoding/json" + "fmt" "log" "net/http" "strconv" ) +// func Counter(S []string) map[string]int { +// //List := strings.Fields(S) +// count := make(map[string]int) +// for _, Lang := range S { +// _, ok := count[Lang] +// if ok { +// count[Lang] += 1 +// } else { +// count[Lang] = 1 +// } +// } +// return count +// } + func HandlerLanguages(w http.ResponseWriter, r *http.Request) { var I []IDLang var L Language + var Code []CodeType URL1 := "https://git.gvk.idi.ntnu.no/api/v4/projects" // main url URL2 := "https://git.gvk.idi.ntnu.no/api/v4/projects?private_token=" // url for token @@ -48,6 +64,8 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) { I = append(I, TempID...) // adds test to I + fmt.Println("len: ", len(I)) + } for i := range I { // loops true length of I @@ -56,16 +74,26 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) { URL = URL + "?private_token=" + auth // adds token to link } + fmt.Println(URL) //**************************************************************** + + var CodeTemp []CodeType + resp = DoRequest(Client, w, URL) // request link - err = json.NewDecoder(resp.Body).Decode(&L.Languages) // decode to language - if err != nil { // check for error + err = json.NewDecoder(resp.Body).Decode(&CodeTemp) // decode to language + if err != nil { // check for error http.Error(w, err.Error(), http.StatusBadRequest) return } + Code = append(Code, CodeTemp...) + } + // for CodeLang, NumCount := range Counter(Code) { + // fmt.Println(CodeLang, "=", NumCount) + // } + limit := QueryGet("limit", "5", r) // gets limit for localhost link TempInt, err := strconv.Atoi(limit) // turns sting to int diff --git a/assignment2/structs.go b/assignment2/structs.go index 2aab591042d230262fd67ad65cd226e106fff1ca..7e16e7635b08a1243ff461cc5cd16b46afb5b650 100644 --- a/assignment2/structs.go +++ b/assignment2/structs.go @@ -28,7 +28,8 @@ type IDLang struct { } type CodeType struct { - Go string `json:"go"` + Codes string + Num int } type Language struct {