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

Commit b77ddf5

Browse files
committed
update server
1 parent f585482 commit b77ddf5

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func SetupCache() {
1414
Password: conf.Redis.Password,
1515
DB: conf.Redis.DB,
1616
})
17-
pong, err := client.Ping(context.Background()).Result()
17+
_, err := client.Ping(context.Background()).Result()
1818
if err != nil {
1919
logger.Fatal("Failed to connect to Redis server: ", err)
2020
} else {

main.go

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
11
package main
22

3-
import (
4-
"fmt"
5-
"github.com/kataras/iris/v12"
6-
)
7-
83
func main() {
9-
app := iris.Default()
10-
{
11-
app.Get("/user/{username:string}", UserAPI)
12-
app.Get("/repo/{username:string}/{repo:string}", RepoAPI)
13-
}
14-
154
SetupLogger()
165
ReadConfig()
176
ReadToken()
187
SetupCache()
19-
20-
app.Listen(fmt.Sprintf(":%d", conf.Server.Port))
21-
}
22-
23-
func UserAPI(ctx iris.Context) {
24-
username := ctx.Params().Get("username")
25-
data, err, code := AnalysisUser(username)
26-
if err != nil {
27-
ThrowError(ctx, err.Error(), code)
28-
} else {
29-
ctx.JSON(data)
30-
}
31-
}
32-
33-
func RepoAPI(ctx iris.Context) {
34-
username, repo := ctx.Params().Get("username"), ctx.Params().Get("repo")
35-
data, err, code := AnalysisRepo(username, repo)
36-
if err != nil {
37-
ThrowError(ctx, err.Error(), code)
38-
} else {
39-
ctx.JSON(data)
40-
}
8+
RunServer()
419
}

server.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/kataras/iris/v12"
6+
)
7+
8+
func RunServer() {
9+
app := iris.Default()
10+
{
11+
app.Get("/user/{username:string}", UserAPI)
12+
app.Get("/repo/{username:string}/{repo:string}", RepoAPI)
13+
}
14+
app.Listen(fmt.Sprintf(":%d", conf.Server.Port))
15+
}
16+
17+
func UserAPI(ctx iris.Context) {
18+
username := ctx.Params().Get("username")
19+
data, err, code := AnalysisUser(username)
20+
if err != nil {
21+
ThrowError(ctx, err.Error(), code)
22+
} else {
23+
ctx.JSON(data)
24+
}
25+
}
26+
27+
func RepoAPI(ctx iris.Context) {
28+
username, repo := ctx.Params().Get("username"), ctx.Params().Get("repo")
29+
data, err, code := AnalysisRepo(username, repo)
30+
if err != nil {
31+
ThrowError(ctx, err.Error(), code)
32+
} else {
33+
ctx.JSON(data)
34+
}
35+
}

0 commit comments

Comments
 (0)