Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cloud - Assignment 2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hans Kristian Hoel
Cloud - Assignment 2
Commits
27ee9bd7
Commit
27ee9bd7
authored
5 years ago
by
Hans Kristian Hoel
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
assignment2/go.mod
+1
-1
1 addition, 1 deletion
assignment2/go.mod
assignment2/language.go
+15
-4
15 additions, 4 deletions
assignment2/language.go
assignment2/structs.go
+5
-0
5 additions, 0 deletions
assignment2/structs.go
with
21 additions
and
5 deletions
assignment2/go.mod
+
1
−
1
View file @
27ee9bd7
This diff is collapsed.
Click to expand it.
assignment2/language.go
+
15
−
4
View file @
27ee9bd7
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
assignment2/structs.go
+
5
−
0
View file @
27ee9bd7
...
@@ -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"`
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment