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

i have sortet the languages fro a map in to a struckt so that i displays the languag used the most

parent f32c320f
No related branches found
No related tags found
Loading
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"sort"
"strconv" "strconv"
) )
...@@ -96,12 +97,22 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) { ...@@ -96,12 +97,22 @@ func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
} }
for CodeLang, NumCount := range Counter(Code) { var Lang []TestLang // making a temp struckt
fmt.Println(CodeLang, "=", NumCount)
CodeTypes := Counter(Code) // make a map[string]int that have codelanguag counted
fmt.Println("test: ", CodeTypes) //*********************************************
for k, v := range CodeTypes { // loops over map
Lang = append(Lang, TestLang{k, v}) // sets map values in to struct
} }
// fmt.Println(Code)
L.Languages = append(L.Languages, Code...) sort.Slice(Lang, func(i, j int) bool { return Lang[i].Count > Lang[j].Count }) //sort struct from highest to lovest int
fmt.Println(Lang) //****************************************************************
for i := range Lang { // loops over struct
L.Languages = append(L.Languages, Lang[i].Lang) // sets string from struct inn to L.Languages
}
limit := QueryGet("limit", "5", r) // gets limit for localhost link limit := QueryGet("limit", "5", r) // gets limit for localhost link
......
...@@ -27,6 +27,11 @@ type IDLang struct { ...@@ -27,6 +27,11 @@ type IDLang struct {
ID int `json:"id"` ID int `json:"id"`
} }
type TestLang struct {
Lang string
Count int
}
type Language struct { type Language struct {
Languages []string `json:"lagnguages"` Languages []string `json:"lagnguages"`
Auth bool `json:"auth"` Auth bool `json:"auth"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment