refactor: 按go modules规范重构

This commit is contained in:
2026-04-15 15:19:39 +08:00
parent 8c5cd3705a
commit 5d4bf761b8
21 changed files with 524 additions and 679 deletions
@@ -0,0 +1,41 @@
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"knowledge-graph-backend/internal/service"
)
type SearchHandler struct {
service service.GraphService
}
func NewSearchHandler(svc service.GraphService) *SearchHandler {
return &SearchHandler{
service: svc,
}
}
// @Summary 搜索节点
// @Description 根据关键词搜索知识图谱中的节点
// @Produce json
// @Param q query string true "搜索关键词"
// @Success 200 {object} model.SearchResponse "成功"
// @Failure 400 {object} model.ErrorResponse "请求错误"
// @Failure 500 {object} model.ErrorResponse "内部错误"
// @Router /api/search [get]
func (h *SearchHandler) SearchNodes(c *gin.Context) {
query := c.Query("q")
if query == "" {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Bad Request",
"message": "Query parameter 'q' is required",
})
return
}
results := h.service.SearchNodes(query)
c.JSON(http.StatusOK, results)
}