-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
210 lines (171 loc) · 5.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package main
import (
"fmt"
"githubembedapi/card"
"githubembedapi/card/style"
"githubembedapi/commit_activity"
"githubembedapi/icons"
"githubembedapi/languageCard"
"githubembedapi/organization"
"githubembedapi/project"
"githubembedapi/rank"
"githubembedapi/skills"
"githubembedapi/stats"
"githubembedapi/streak"
"net/http"
"strconv"
"strings"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
router := gin.Default()
router.StaticFS("/static", http.Dir("./static"))
// router.StaticFile("/.env", "/.env")
// router.GET("/ranklist", rankList)
router.GET("/icon", icon)
router.GET("/skills", getSkills)
router.GET("/mostactivity", getMostactivity)
router.GET("/project", projectcard)
router.GET("/commitactivity", repositoryCommitActivity)
router.GET("/streak", userstreak)
router.GET("/languageCard", language)
router.GET("/stats", statscard)
router.GET("/radar", radar)
router.GET("/line", line)
router.GET("/bar", bar)
err := godotenv.Load(".env")
if err != nil {
fmt.Printf("Error loading .env file")
}
// router.Run("localhost:8080")
router.Run()
}
func radar(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
var radar card.Radar
values := card.UrlSplit(c, "values")
labels := card.UrlSplit(c, "labels")
for _, v := range values {
val, _ := strconv.Atoi(v)
radar.Values = append(radar.Values, val)
}
radar.Labels = labels
radar.Color = "#0000ff"
radar.Width = 300
radar.Height = 300
radar.Grid = true
c.String(http.StatusOK, card.RadarChart(radar))
}
func line(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
var line card.Line
values := card.UrlSplit(c, "values")
for _, v := range values {
val, _ := strconv.Atoi(v)
line.Values = append(line.Values, val)
}
line.Width = 300
line.Height = 300
line.Color = "#0074d9"
line.GridVertical = true
line.GridHorizontal = true
c.String(http.StatusOK, card.LineChart(line))
}
func bar(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
var bar card.Bar
values := card.UrlSplit(c, "values")
labels := card.UrlSplit(c, "labels")
for _, v := range values {
val, _ := strconv.Atoi(v)
bar.Values = append(bar.Values, val)
}
bar.Labels = labels
bar.Width = 300
bar.Height = 300
bar.Grid = true
bar.Vertical = true
c.String(http.StatusOK, card.BarChartVertical(bar))
}
func statscard(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
user := c.Request.FormValue("user")
title := c.Request.FormValue("title")
hide := card.UrlSplit(c, "hide")
var color = style.CheckTheme(c)
c.String(http.StatusOK, stats.Stats(title, user, hide, color))
}
func getMostactivity(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
org := c.Request.FormValue("org")
title := c.Request.FormValue("title")
var color = style.CheckTheme(c)
c.String(http.StatusOK, organization.MostactivityCard(title, org, color))
}
func repositoryCommitActivity(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
user := c.Request.FormValue("user")
repo := c.Request.FormValue("repo")
title := c.Request.FormValue("title")
var hide_week string = c.Request.FormValue("hide_week")
var color = style.CheckTheme(c)
c.String(http.StatusOK, commit_activity.RepositoryCommitActivity(title, user, repo, hide_week, color))
}
func projectcard(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
user := c.Request.FormValue("user")
repo := c.Request.FormValue("repo")
var color = style.CheckTheme(c)
c.String(http.StatusOK, project.Project(user, repo, color))
}
func language(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
title := c.Request.FormValue("title")
user := c.Request.FormValue("user")
org := c.Request.FormValue("organization")
langs_count := c.Request.FormValue("langs_count")
var isOrg bool = false
if len(org) > 0 && len(user) < 1 {
user = org
isOrg = true
}
var color = style.CheckTheme(c)
c.String(http.StatusOK, languageCard.LanguageCard(title, user, langs_count, color, isOrg))
}
func rankList(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
users := card.UrlSplit(c, "users")
title := c.Request.FormValue("title")
var color = style.CheckTheme(c)
c.String(http.StatusOK, rank.Rankcard(title, users, color))
}
func userstreak(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
user := c.Request.FormValue("user")
hide_title := c.Request.FormValue("hide_title")
var color = style.CheckTheme(c)
c.String(http.StatusOK, streak.Streak(user, hide_title, color))
}
func getSkills(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
// Define styles
languages := strings.Split(c.Request.URL.Query().Get("languages"), ",")
title := c.Request.FormValue("title")
var color = style.CheckTheme(c)
c.String(http.StatusOK, skills.Skills(title, languages, color))
}
func icon(c *gin.Context) {
c.Header("Content-Type", "image/svg+xml")
icon := c.Request.FormValue("icon")
size := c.Request.FormValue("size")
if len(size) < 1 {
size = "60"
}
svgIcon := icons.Icons(icon)
svgIcon = strings.ReplaceAll(svgIcon, `width='20'`, fmt.Sprintf(`width='%v'`, size))
svgIcon = strings.ReplaceAll(svgIcon, `height='20'`, fmt.Sprintf(`height='%v'`, size))
svgIcon = strings.ReplaceAll(svgIcon, `x='10'`, ``)
svgIcon = strings.ReplaceAll(svgIcon, `y='10'`, ``)
c.String(http.StatusOK, svgIcon)
}