Skip to content

Commit 3f264a2

Browse files
committed
refactor: rename route handler and parameters for redirect functionality
1 parent dd397ce commit 3f264a2

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

internal/handler/handler_factory.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"github.com/scutrobotlab/rm-schedule/internal/svc"
66
)
77

8-
type RouteHandlerParam struct {
8+
// RedirectRouteHandlerParam 定义重定向路由处理器的参数
9+
type RedirectRouteHandlerParam struct {
910
Name string
1011
CacheControl string
1112
OriginalUrl string
@@ -14,7 +15,8 @@ type RouteHandlerParam struct {
1415
Data []byte
1516
}
1617

17-
func RouteHandlerFactory(param RouteHandlerParam) func(c iris.Context) {
18+
// RedirectRouteHandlerFactory 处理重定向路由的工厂函数
19+
func RedirectRouteHandlerFactory(param RedirectRouteHandlerParam) func(c iris.Context) {
1820
return func(c iris.Context) {
1921
if param.SeasonMap != nil {
2022
season := c.URLParam("season")

internal/router/redirect.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package router
2+
3+
import (
4+
"github.com/scutrobotlab/rm-schedule/internal/common"
5+
"github.com/scutrobotlab/rm-schedule/internal/handler"
6+
"github.com/scutrobotlab/rm-schedule/internal/static"
7+
)
8+
9+
// RedirectParams 定义重定向路由的参数
10+
var RedirectParams = map[string]handler.RedirectRouteHandlerParam{
11+
common.UpstreamNameGroupRankInfo: {
12+
Name: common.UpstreamNameGroupRankInfo,
13+
Static: false,
14+
CacheControl: "public, max-age=5",
15+
OriginalUrl: common.UpstreamUrlGroupRankInfo,
16+
Data: static.GroupRankInfoBytes,
17+
SeasonMap: map[string][]byte{
18+
"2024": static.GroupRankInfoBytes2024,
19+
},
20+
},
21+
common.UpstreamNameRobotData: {
22+
Name: common.UpstreamNameRobotData,
23+
Static: false,
24+
CacheControl: "public, max-age=5",
25+
OriginalUrl: common.UpstreamUrlRobotData,
26+
Data: static.RobotDataBytes,
27+
SeasonMap: nil,
28+
},
29+
common.UpstreamNameSchedule: {
30+
Name: common.UpstreamNameSchedule,
31+
Static: false,
32+
CacheControl: "public, max-age=5",
33+
OriginalUrl: common.UpstreamUrlSchedule,
34+
Data: static.ScheduleBytes,
35+
SeasonMap: map[string][]byte{
36+
"2024": static.ScheduleBytes2024,
37+
},
38+
},
39+
}

internal/router/router.go

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,17 @@ import (
44
"github.com/kataras/iris/v12"
55
"github.com/scutrobotlab/rm-schedule/internal/common"
66
"github.com/scutrobotlab/rm-schedule/internal/handler"
7-
"github.com/scutrobotlab/rm-schedule/internal/static"
87
)
98

10-
var Params = map[string]handler.RouteHandlerParam{
11-
common.UpstreamNameGroupRankInfo: {
12-
Name: common.UpstreamNameGroupRankInfo,
13-
Static: false,
14-
CacheControl: "public, max-age=5",
15-
OriginalUrl: common.UpstreamUrlGroupRankInfo,
16-
Data: static.GroupRankInfoBytes,
17-
SeasonMap: map[string][]byte{
18-
"2024": static.GroupRankInfoBytes2024,
19-
},
20-
},
21-
common.UpstreamNameRobotData: {
22-
Name: common.UpstreamNameRobotData,
23-
Static: false,
24-
CacheControl: "public, max-age=5",
25-
OriginalUrl: common.UpstreamUrlRobotData,
26-
Data: static.RobotDataBytes,
27-
SeasonMap: nil,
28-
},
29-
common.UpstreamNameSchedule: {
30-
Name: common.UpstreamNameSchedule,
31-
Static: false,
32-
CacheControl: "public, max-age=5",
33-
OriginalUrl: common.UpstreamUrlSchedule,
34-
Data: static.ScheduleBytes,
35-
SeasonMap: map[string][]byte{
36-
"2024": static.ScheduleBytes2024,
37-
},
38-
},
39-
}
40-
419
// Router defines the router for this service
4210
func Router(r *iris.Application, frontend string) {
4311
api := r.Party("/api")
4412
api.Get("/static/*path", handler.RMStaticHandler)
4513
api.Get("/mp/match", handler.MpMatchHandler)
4614
api.Get("/rank", handler.RankListHandler)
47-
api.Get("/group_rank_info", handler.RouteHandlerFactory(Params[common.UpstreamNameGroupRankInfo]))
48-
api.Get("/robot_data", handler.RouteHandlerFactory(Params[common.UpstreamNameRobotData]))
49-
api.Get("/schedule", handler.RouteHandlerFactory(Params[common.UpstreamNameSchedule]))
15+
api.Get("/group_rank_info", handler.RedirectRouteHandlerFactory(RedirectParams[common.UpstreamNameGroupRankInfo]))
16+
api.Get("/robot_data", handler.RedirectRouteHandlerFactory(RedirectParams[common.UpstreamNameRobotData]))
17+
api.Get("/schedule", handler.RedirectRouteHandlerFactory(RedirectParams[common.UpstreamNameSchedule]))
5018

5119
r.HandleDir("/", iris.Dir(frontend), iris.DirOptions{
5220
IndexName: "index.html",

0 commit comments

Comments
 (0)