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

manage to decode languages to a map

parent 6939b9a2
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,13 @@ import (
"strconv"
)
// func Counter(S []string) map[string]int {
// func Counter(S []map[string]float64) map[string]int {
// //List := strings.Fields(S)
// count := make(map[string]int)
// for _, Lang := range S {
// _, ok := count[Lang]
// if ok {
// count[Lang] += 1func Counter(S []map[string]float64) map[string]int {
// //List := strings.Fields(S)
// count := make(map[string]int)
// for _, Lang := range S {
......@@ -21,12 +27,18 @@ import (
// }
// return count
// }
// } else {
// count[Lang] = 1
// }
// }
// return count
// }
func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
var I []IDLang
var L Language
var Code []CodeType
var Code []map[string]float64
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
......@@ -41,6 +53,8 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
}
fmt.Println(URL3)
resp := DoRequest(Client, w, URL3) // request link
PageTot, err := strconv.Atoi(resp.Header.Get("X-Total-Pages")) // gets count of total pages
......@@ -48,6 +62,7 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Println(PageTot) // ***************************************************************
for i := 1; i <= PageTot; i++ { // loops true total pages
URL := URL3 + "&page=" + strconv.Itoa(i) // sets url to one page
......@@ -76,7 +91,7 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
fmt.Println(URL) //****************************************************************
var CodeTemp []CodeType
var CodeTemp map[string]float64
resp = DoRequest(Client, w, URL) // request link
......@@ -86,7 +101,7 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
return
}
Code = append(Code, CodeTemp...)
Code = append(Code, CodeTemp)
}
......
......@@ -28,8 +28,7 @@ type IDLang struct {
}
type CodeType struct {
Codes string
Num int
CodeMap map[string]float64
}
type Language struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment