Skip to content

Commit c2dea80

Browse files
committed
refactor: reorder header checks in ScheduleHandler and GroupRankInfoHandler
1 parent 4c373ac commit c2dea80

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

internal/handler/group_rank_info.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ package handler
33
import (
44
"github.com/kataras/iris/v12"
55
"github.com/scutrobotlab/rm-schedule/internal/job"
6+
"github.com/scutrobotlab/rm-schedule/internal/static"
67
"github.com/scutrobotlab/rm-schedule/internal/svc"
78
)
89

910
const (
11+
GroupRankInfoStatic = false
1012
GroupRankInfoCacheControl = "public, max-age=5"
1113
)
1214

1315
func GroupRankInfoHandler(c iris.Context) {
16+
if GroupRankInfoStatic {
17+
c.Header("Cache-Control", "no-cache")
18+
c.ContentType("application/json")
19+
c.Write(static.GroupRankInfoBytes)
20+
return
21+
}
22+
1423
if c.GetHeader("Tencent-Acceleration-Domain-Name") != "" {
1524
c.Header("Cache-Control", GroupRankInfoCacheControl)
1625
c.Redirect(job.GroupRankInfoUrl, 301)

internal/handler/schedule.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ const (
1313
)
1414

1515
func ScheduleHandler(c iris.Context) {
16-
// 是否存在 Tencent-Acceleration-Domain-Name
17-
if c.GetHeader("Tencent-Acceleration-Domain-Name") != "" {
18-
c.Header("Cache-Control", ScheduleCacheControl)
19-
c.Redirect(job.ScheduleUrl, 301)
20-
return
21-
}
22-
2316
if ScheduleStatic {
2417
c.Header("Cache-Control", "no-cache")
2518
c.ContentType("application/json")
2619
c.Write(static.ScheduleBytes)
2720
return
2821
}
2922

23+
// 是否存在 Tencent-Acceleration-Domain-Name
24+
if c.GetHeader("Tencent-Acceleration-Domain-Name") != "" {
25+
c.Header("Cache-Control", ScheduleCacheControl)
26+
c.Redirect(job.ScheduleUrl, 301)
27+
return
28+
}
29+
3030
if cached, b := svc.Cache.Get("schedule"); b {
3131
c.Header("Cache-Control", ScheduleCacheControl)
3232
c.ContentType("application/json")

0 commit comments

Comments
 (0)