🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
This commit is contained in:
commit
6981148727
107 files changed
+12463
No files matched your search
@@ -0,0 +1,90 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fanqie/internal/fqapi"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// HandleSearch 搜索处理
|
||||
func HandleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
incrementTotal()
|
||||
incrementSearch()
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
query := r.URL.Query().Get("query")
|
||||
if query == "" {
|
||||
query = r.URL.Query().Get("key")
|
||||
}
|
||||
|
||||
offsetStr := r.URL.Query().Get("offset")
|
||||
offset := 0
|
||||
if offsetStr != "" {
|
||||
offset, _ = strconv.Atoi(offsetStr)
|
||||
}
|
||||
|
||||
tabTypeStr := r.URL.Query().Get("tab_type")
|
||||
tabType := 3
|
||||
if tabTypeStr != "" {
|
||||
tabType, _ = strconv.Atoi(tabTypeStr)
|
||||
}
|
||||
|
||||
result, err := fqapi.HandleBookSearch(query, offset, tabType)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, `{"code": -1, "msg": "搜索失败: %s"}`, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, result)
|
||||
}
|
||||
|
||||
// HandleDetail 详情处理
|
||||
func HandleDetail(w http.ResponseWriter, r *http.Request) {
|
||||
incrementTotal()
|
||||
incrementDetail()
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
bookID := r.URL.Query().Get("book_id")
|
||||
|
||||
result, err := fqapi.HandleGetDetail(bookID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, `{"code": -1, "msg": "获取详情失败: %s"}`, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, result)
|
||||
}
|
||||
|
||||
// HandleCatalog 目录处理
|
||||
func HandleCatalog(w http.ResponseWriter, r *http.Request) {
|
||||
incrementTotal()
|
||||
incrementCatalog()
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
bookID := r.URL.Query().Get("book_id")
|
||||
|
||||
result, err := fqapi.HandleGetCatalog(bookID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, `{"code": -1, "msg": "获取目录失败: %s"}`, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, result)
|
||||
}
|
||||
|
||||
// HandleMultiDetail 批量详情处理
|
||||
func HandleMultiDetail(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
bookID := r.URL.Query().Get("book_id")
|
||||
|
||||
result, err := fqapi.HandleGetMultiDetail(bookID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, `{"code": -1, "msg": "批量获取详情失败: %s"}`, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, result)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user