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

Commit 6549a74

Browse files
committed
update backend structure
1 parent 30820bc commit 6549a74

6 files changed

Lines changed: 126 additions & 143 deletions

File tree

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: Deployment
22
on:
3-
push:
4-
branches:
5-
- main
3+
release:
4+
types: [published]
65

76
jobs:
87
release:
@@ -43,14 +42,16 @@ jobs:
4342
mkdir deploy/app
4443
mv app deploy/app/
4544
46-
- name: Commit Migration
45+
- name: Pack Application
4746
run: |
48-
git config --global user.name "GitHub Actions"
49-
git config --global user.email "actions@github.com"
50-
cd deploy
51-
git checkout -b deploy
52-
git add .
53-
git commit -m "deploy"
54-
git push --force --quiet "https://${{ secrets.GITHUB_TOKEN }}@github.com/zmh-program/code-statistic.git"
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
47+
zip -r deployment.zip ./deploy/*
48+
49+
- name: Upload Package
50+
uses: actions/upload-release-asset@v1.0.2
51+
with:
52+
upload_url: ${{ github.event.release.upload_url }}
53+
asset_path: ./deployment.zip
54+
asset_name: deployment.zip
55+
asset_content_type: application/zip
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.TOKEN }}

conf.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

logger.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

main.go

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,68 @@
11
package main
22

3+
import (
4+
"fmt"
5+
"github.com/kataras/iris/v12"
6+
"github.com/sirupsen/logrus"
7+
"github.com/spf13/viper"
8+
"os"
9+
"strings"
10+
"time"
11+
)
12+
13+
var logger = logrus.New()
14+
15+
type Formatter struct {
16+
}
17+
18+
func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
19+
timestamp := time.Now().Format("2006/01/02 15:04")
20+
level := strings.ToUpper(entry.Level.String())
21+
message := entry.Message
22+
23+
var color string
24+
switch entry.Level {
25+
case logrus.DebugLevel:
26+
color = "\u001B[33m"
27+
case logrus.InfoLevel:
28+
color = "\033[32m"
29+
case logrus.WarnLevel:
30+
color = "\033[33m"
31+
case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
32+
color = "\033[31m"
33+
default:
34+
color = "\033[0m"
35+
}
36+
37+
return []byte(fmt.Sprintf("%s[%s]\u001B[0m %s - %s\n", color, level, timestamp, message)), nil
38+
}
39+
340
func main() {
4-
SetupLogger()
5-
ReadConfig()
6-
ReadToken()
41+
logger.SetLevel(logrus.DebugLevel)
42+
logger.SetFormatter(&Formatter{})
43+
44+
_, err := os.Stat("config.yaml")
45+
if err != nil && os.IsNotExist(err) {
46+
logger.Fatal("Config file (config.yaml) not found!")
47+
}
48+
49+
viper.SetConfigFile("config.yaml")
50+
if err := viper.ReadInConfig(); err != nil {
51+
logger.Fatalf("Failed to read config file: %v", err)
52+
}
53+
if err := viper.Unmarshal(&conf); err != nil {
54+
logger.Fatalf("Failed to unmarshal config file: %v", err)
55+
}
56+
57+
tokenList = GetTokenFromEnv()
58+
ValidateToken()
759
SetupCache()
8-
RunServer()
60+
61+
app := iris.Default()
62+
{
63+
app.Get("/api/user/{username:string}", CachedHandler(UserAPI))
64+
app.Get("/api/repo/{username:string}/{repo:string}", CachedHandler(RepoAPI))
65+
app.Get("/api/contributor/{username:string}/{repo:string}", CachedHandler(ContributorAPI))
66+
}
67+
app.Listen(fmt.Sprintf(":%d", conf.Server.Port))
968
}

server.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
package main
22

33
import (
4-
"fmt"
54
"github.com/kataras/iris/v12"
65
)
76

8-
func RunServer() {
9-
app := iris.Default()
10-
{
11-
app.Get("/api/user/{username:string}", CachedHandler(UserAPI))
12-
app.Get("/api/repo/{username:string}/{repo:string}", CachedHandler(RepoAPI))
13-
app.Get("/api/contributor/{username:string}/{repo:string}", CachedHandler(ContributorAPI))
14-
}
15-
app.Listen(fmt.Sprintf(":%d", conf.Server.Port))
16-
}
17-
187
func UserAPI(ctx iris.Context) {
198
username := ctx.Params().Get("username")
209
data := AnalysisUser(username)

0 commit comments

Comments
 (0)