feat: 编写swagger注释并生成文档
This commit is contained in:
@@ -7,13 +7,21 @@ import (
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
|
||||
"knowledge-graph-backend/config"
|
||||
"knowledge-graph-backend/docs"
|
||||
"knowledge-graph-backend/handlers"
|
||||
neo4jClient "knowledge-graph-backend/neo4j"
|
||||
"knowledge-graph-backend/services"
|
||||
)
|
||||
|
||||
// @title 知识图谱 API
|
||||
// @version 1.0.0
|
||||
// @description 知识图谱后端服务,提供图数据查询、节点搜索等功能
|
||||
// @host localhost:8080
|
||||
// @BasePath /
|
||||
func main() {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
@@ -33,6 +41,14 @@ func main() {
|
||||
|
||||
router.Use(cors.New(cfg.CORS.ToGinConfig()))
|
||||
|
||||
docs.SwaggerInfo.BasePath = "/"
|
||||
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// @Summary 健康检查
|
||||
// @Description 检查服务是否正常运行
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]string "成功"
|
||||
// @Router /health [get]
|
||||
router.GET("/health", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
|
||||
Reference in New Issue
Block a user