@@ -50,84 +50,80 @@ func InitHandleRouter(cfg *config.Config, r *touka.Engine, version string) {
5050}
5151
5252func SizeLimitHandler (cfg * config.Config , c * touka.Context ) {
53- sizeLimit := cfg .Server .SizeLimit
5453 c .SetHeader ("Content-Type" , "application/json" )
55- c .JSON (200 , ( map [ string ] any {
56- " MaxResponseBodySize" : sizeLimit ,
57- }))
54+ c .JSON (200 , SizeLimitResponse {
55+ MaxResponseBodySize : cfg . Server . SizeLimit ,
56+ })
5857}
5958
6059func WhiteListStatusHandler (cfg * config.Config , c * touka.Context ) {
6160 c .SetHeader ("Content-Type" , "application/json" )
62- c .JSON (200 , ( map [ string ] any {
63- " Whitelist" : cfg .Whitelist .Enabled ,
64- }))
61+ c .JSON (200 , WhitelistStatusResponse {
62+ Whitelist : cfg .Whitelist .Enabled ,
63+ })
6564}
6665
6766func BlackListStatusHandler (cfg * config.Config , c * touka.Context ) {
6867 c .SetHeader ("Content-Type" , "application/json" )
69- c .JSON (200 , ( map [ string ] any {
70- " Blacklist" : cfg .Blacklist .Enabled ,
71- }))
68+ c .JSON (200 , BlacklistStatusResponse {
69+ Blacklist : cfg .Blacklist .Enabled ,
70+ })
7271}
7372
7473func CorsStatusHandler (cfg * config.Config , c * touka.Context ) {
7574 c .SetHeader ("Content-Type" , "application/json" )
76- c .JSON (200 , ( map [ string ] any {
77- " Cors" : cfg .Server .Cors ,
78- }))
75+ c .JSON (200 , CorsStatusResponse {
76+ Cors : cfg .Server .Cors ,
77+ })
7978}
8079
8180func HealthcheckHandler (c * touka.Context ) {
8281 c .SetHeader ("Content-Type" , "application/json" )
83- c .JSON (200 , (map [string ]any {
84- "Status" : "OK" ,
85- "Repo" : "WJQSERVER-STUDIO/GHProxy" ,
86- "Author" : "WJQSERVER-STUDIO" ,
87- }))
82+ // 复制预定义的固定响应,避免重复分配
83+ resp := baseHealthcheckResponse
84+ c .JSON (200 , resp )
8885}
8986
9087func VersionHandler (c * touka.Context , version string ) {
9188 c .SetHeader ("Content-Type" , "application/json" )
92- c .JSON (200 , (map [string ]any {
93- "Version" : version ,
94- "Repo" : "WJQSERVER-STUDIO/GHProxy" ,
95- "Author" : "WJQSERVER-STUDIO" ,
96- }))
89+ // 复制预定义的固定响应并填充动态字段
90+ resp := baseVersionResponse
91+ resp .Version = version
92+ c .JSON (200 , resp )
9793}
9894
9995func RateLimitStatusHandler (cfg * config.Config , c * touka.Context ) {
10096 c .SetHeader ("Content-Type" , "application/json" )
101- c .JSON (200 , ( map [ string ] any {
102- " RateLimit" : cfg .RateLimit .Enabled ,
103- }))
97+ c .JSON (200 , RateLimitStatusResponse {
98+ RateLimit : cfg .RateLimit .Enabled ,
99+ })
104100}
105101
106102func RateLimitLimitHandler (cfg * config.Config , c * touka.Context ) {
107103 c .SetHeader ("Content-Type" , "application/json" )
108- c .JSON (200 , ( map [ string ] any {
109- " RatePerMinute" : cfg .RateLimit .RatePerMinute ,
110- }))
104+ c .JSON (200 , RateLimitLimitResponse {
105+ RatePerMinute : cfg .RateLimit .RatePerMinute ,
106+ })
111107}
112108
113109func SmartGitStatusHandler (cfg * config.Config , c * touka.Context ) {
114110 c .SetHeader ("Content-Type" , "application/json" )
115- c .JSON (200 , ( map [ string ] any {
116- "enabled" : cfg .GitClone .Mode == "cache" ,
117- }))
111+ c .JSON (200 , SmartGitStatusResponse {
112+ Enabled : cfg .GitClone .Mode == "cache" ,
113+ })
118114}
119115
120116func shellNestStatusHandler (cfg * config.Config , c * touka.Context ) {
121117 c .SetHeader ("Content-Type" , "application/json" )
122- c .JSON (200 , ( map [ string ] any {
123- "enabled" : cfg .Shell .Editor ,
124- }))
118+ c .JSON (200 , ShellNestStatusResponse {
119+ Enabled : cfg .Shell .Editor ,
120+ })
125121}
126122
127123func ociProxyStatusHandler (cfg * config.Config , c * touka.Context ) {
128124 c .SetHeader ("Content-Type" , "application/json" )
129- c .JSON (200 , ( map [ string ] any {
130- "enabled" : cfg .Docker .Enabled ,
131- "target" : cfg .Docker .Target ,
132- }))
125+ c .JSON (200 , OCIDockerResponse {
126+ Enabled : cfg .Docker .Enabled ,
127+ Target : cfg .Docker .Target ,
128+ })
133129}
0 commit comments