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

Commit abd17b8

Browse files
committed
implement /api/search/resources
1 parent f916713 commit abd17b8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

handlers/resources.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package handlers
2+
3+
import (
4+
"helios/config"
5+
"net/http"
6+
7+
"github.com/bytedance/sonic"
8+
)
9+
10+
func ResourcesHandler(w http.ResponseWriter, r *http.Request) {
11+
if r.Method != http.MethodGet {
12+
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
13+
return
14+
}
15+
16+
// 将 map 转换为 list
17+
apiSites := config.GlobalConfig.APISites
18+
resources := make([]interface{}, 0, len(apiSites))
19+
20+
for _, site := range apiSites {
21+
resources = append(resources, site)
22+
}
23+
24+
w.Header().Set("Content-Type", "application/json")
25+
sonic.ConfigDefault.NewEncoder(w).Encode(resources)
26+
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func main() {
4949
// 其他接口都需要认证中间件
5050
http.HandleFunc("/api/search", handlers.AuthMiddleware(handlers.SearchHandler))
5151
http.HandleFunc("/api/search/ws", handlers.AuthMiddleware(handlers.SSESearchHandler))
52+
http.HandleFunc("/api/search/resources", handlers.AuthMiddleware(handlers.ResourcesHandler))
5253
http.HandleFunc("/api/detail", handlers.AuthMiddleware(handlers.DetailHandler))
5354
http.HandleFunc("/api/favorites", handlers.AuthMiddleware(handlers.FavoritesHandler))
5455
http.HandleFunc("/api/searchhistory", handlers.AuthMiddleware(handlers.SearchHistoryHandler))

0 commit comments

Comments
 (0)