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

Commit 39fb9a3

Browse files
committed
update language analysis
1 parent 168a1a9 commit 39fb9a3

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

cache.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ func SetupCache() {
2020
if err != nil {
2121
logger.Fatal("Failed to connect to Redis server: ", err)
2222
} else {
23-
logger.Debug("Connected to Redis server successfully.")
23+
logger.Debug("Connected to Redis server successfully")
24+
}
25+
if conf.Debug {
26+
cache.FlushAll(context.Background())
27+
logger.Debug("Flushed all cache")
2428
}
2529
}
2630

conf.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import (
1010
)
1111

1212
type Config struct {
13+
Debug bool
14+
1315
Server struct {
1416
Port int
1517
}
18+
1619
Redis struct {
1720
Host string
1821
Port int
@@ -48,7 +51,7 @@ func ValidateToken() {
4851
if len(tokenList) == 0 {
4952
logger.Fatal("No token found! Please set TOKEN environment variable.")
5053
}
51-
logger.Debug(fmt.Sprintf("Found %d available token(s).", len(tokenList)))
54+
logger.Debug(fmt.Sprintf("Found %d available token(s)", len(tokenList)))
5255
}
5356

5457
func ReadToken() {

config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
debug: true
12
server:
23
port: 8080
34

@@ -6,3 +7,4 @@ redis:
67
port: 6379
78
password: ""
89
db: 0
10+
expiration: 7200

utils.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/sirupsen/logrus"
88
"io"
99
"net/http"
10+
"sort"
1011
)
1112

1213
// generate at https://github.com/ozh/github-colors/blob/master/colors.json
@@ -96,14 +97,27 @@ func Get(uri string, ptr interface{}) (err error) {
9697
return nil
9798
}
9899

99-
func CountLanguages(languages map[string]float64) map[string]string {
100+
func CountLanguages(languages map[string]float64) []map[string]any {
100101
total := 0.
101-
res := map[string]string{}
102+
103+
var res []map[string]any
102104
for _, v := range languages {
103105
total += v
104106
}
107+
105108
for k, v := range languages {
106-
res[k] = fmt.Sprintf("%.0f%% (%s)", v/total*100, ScaleConvert(v, false))
109+
res = append(res, map[string]any{
110+
"lang": k,
111+
"value": v,
112+
"percent": v / total * 100,
113+
"color": GetColor(k),
114+
"text": fmt.Sprintf("%.0f%% (%s)", v/total*100, ScaleConvert(v, false)),
115+
})
107116
}
117+
118+
sort.Slice(res, func(i, j int) bool {
119+
return res[i]["value"].(float64) > res[j]["value"].(float64)
120+
})
121+
108122
return res
109123
}

0 commit comments

Comments
 (0)