Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 73a33cb

Browse files
committed
add language analysis
1 parent 0c24790 commit 73a33cb

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func iterRepos(username string) (data []interface{}, err error) {
5959
return res, nil
6060
}
6161

62-
func CollectLanguages(username string, repos []string) (data map[string]int, err error) {
63-
data = make(map[string]int)
62+
func CollectLanguages(username string, repos []interface{}) (data map[string]float64, err error) {
63+
data = make(map[string]float64)
6464
channel := make(chan map[string]interface{}, len(repos))
6565

6666
for _, repo := range repos {
@@ -70,14 +70,14 @@ func CollectLanguages(username string, repos []string) (data map[string]int, err
7070
return
7171
}
7272
channel <- languages
73-
}(username, repo)
73+
}(username, repo.(map[string]interface{})["name"].(string))
7474
}
7575

7676
for range repos {
7777
select {
7878
case languages := <-channel:
7979
for k, v := range languages {
80-
data[k] += v.(int)
80+
data[k] += v.(float64)
8181
}
8282
}
8383
}

main.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,27 @@ func AnalyseUser(ctx iris.Context) {
2929
ThrowError(ctx, iris.StatusInternalServerError, err.Error())
3030
return
3131
}
32-
repo, err := iterRepos(username)
32+
repos, err := iterRepos(username)
33+
if err != nil {
34+
ThrowError(ctx, iris.StatusInternalServerError, err.Error())
35+
return
36+
}
37+
langs, err := CollectLanguages(username, repos)
3338
if err != nil {
3439
ThrowError(ctx, iris.StatusInternalServerError, err.Error())
3540
return
3641
}
3742
ctx.JSON(iris.Map{
38-
"username": username,
39-
"location": res["location"],
40-
"org": res["type"] != "User",
41-
"repos": res["public_repos"],
42-
"follower": ScaleConvert(res["followers"].(float64), true),
43-
"stars": ScaleConvert(Sum(repo, "stargazers_count"), true),
44-
"forks": ScaleConvert(Sum(repo, "forks_count"), true),
45-
"issues": ScaleConvert(Sum(repo, "open_issues_count"), true),
46-
"watchers": ScaleConvert(Sum(repo, "watchers_count"), true),
43+
"username": username,
44+
"location": res["location"],
45+
"org": res["type"] != "User",
46+
"repos": res["public_repos"],
47+
"follower": ScaleConvert(res["followers"].(float64), true),
48+
"stars": ScaleConvert(Sum(repos, "stargazers_count"), true),
49+
"forks": ScaleConvert(Sum(repos, "forks_count"), true),
50+
"issues": ScaleConvert(Sum(repos, "open_issues_count"), true),
51+
"watchers": ScaleConvert(Sum(repos, "watchers_count"), true),
52+
"languages": langs,
4753
})
4854
return
4955
}

0 commit comments

Comments
 (0)