From f93bd879c3167e26201397a8965f9e1d9ca44f77 Mon Sep 17 00:00:00 2001 From: hhs <386998068.com> Date: Mon, 13 Apr 2026 16:16:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E5=86=99swagger=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=B9=B6=E7=94=9F=E6=88=90=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/docs/docs.go | 348 +++++++++++++++++++++++++++++ backend/docs/swagger.json | 324 +++++++++++++++++++++++++++ backend/docs/swagger.yaml | 215 ++++++++++++++++++ backend/go.mod | 16 ++ backend/go.sum | 86 +++++++ backend/handlers/graph_handler.go | 12 + backend/handlers/node_handler.go | 18 ++ backend/handlers/search_handler.go | 8 + backend/main.go | 16 ++ 9 files changed, 1043 insertions(+) create mode 100644 backend/docs/docs.go create mode 100644 backend/docs/swagger.json create mode 100644 backend/docs/swagger.yaml diff --git a/backend/docs/docs.go b/backend/docs/docs.go new file mode 100644 index 0000000..dd224d3 --- /dev/null +++ b/backend/docs/docs.go @@ -0,0 +1,348 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/graph": { + "get": { + "description": "获取知识图谱的全部节点和边数据", + "produces": [ + "application/json" + ], + "summary": "获取图数据", + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.GraphData" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/graph/stats": { + "get": { + "description": "获取知识图谱的节点数、边数等统计信息", + "produces": [ + "application/json" + ], + "summary": "获取图统计信息", + "responses": { + "200": { + "description": "成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/nodes/{id}": { + "get": { + "description": "根据节点 ID 获取知识图谱中的节点详细信息", + "produces": [ + "application/json" + ], + "summary": "获取节点详情", + "parameters": [ + { + "type": "string", + "description": "节点 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.NodeResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "404": { + "description": "节点未找到", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/nodes/{id}/neighbors": { + "get": { + "description": "根据节点 ID 获取其所有邻居节点及关联边", + "produces": [ + "application/json" + ], + "summary": "获取节点邻居", + "parameters": [ + { + "type": "string", + "description": "节点 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.NeighborResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "404": { + "description": "节点未找到", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/search": { + "get": { + "description": "根据关键词搜索知识图谱中的节点", + "produces": [ + "application/json" + ], + "summary": "搜索节点", + "parameters": [ + { + "type": "string", + "description": "搜索关键词", + "name": "q", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.SearchResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + } + }, + "definitions": { + "models.Edge": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "source": { + "type": "string" + }, + "style": { + "type": "object", + "additionalProperties": true + }, + "target": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "models.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "models.GraphData": { + "type": "object", + "properties": { + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Edge" + } + }, + "nodes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + }, + "models.NeighborResponse": { + "type": "object", + "properties": { + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Edge" + } + }, + "nodes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + }, + "models.Node": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "style": { + "type": "object", + "additionalProperties": true + }, + "type": { + "type": "string" + }, + "x": { + "type": "number" + }, + "y": { + "type": "number" + } + } + }, + "models.NodeResponse": { + "type": "object", + "properties": { + "id": { + "type": "string", + "example": "1" + }, + "label": { + "type": "string", + "example": "人工智能" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "type": { + "type": "string", + "example": "概念" + } + } + }, + "models.SearchResponse": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "results": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "1.0.0", + Host: "localhost:8080", + BasePath: "/", + Schemes: []string{}, + Title: "知识图谱 API", + Description: "知识图谱后端服务,提供图数据查询、节点搜索等功能", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json new file mode 100644 index 0000000..6acd2e7 --- /dev/null +++ b/backend/docs/swagger.json @@ -0,0 +1,324 @@ +{ + "swagger": "2.0", + "info": { + "description": "知识图谱后端服务,提供图数据查询、节点搜索等功能", + "title": "知识图谱 API", + "contact": {}, + "version": "1.0.0" + }, + "host": "localhost:8080", + "basePath": "/", + "paths": { + "/api/graph": { + "get": { + "description": "获取知识图谱的全部节点和边数据", + "produces": [ + "application/json" + ], + "summary": "获取图数据", + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.GraphData" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/graph/stats": { + "get": { + "description": "获取知识图谱的节点数、边数等统计信息", + "produces": [ + "application/json" + ], + "summary": "获取图统计信息", + "responses": { + "200": { + "description": "成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/nodes/{id}": { + "get": { + "description": "根据节点 ID 获取知识图谱中的节点详细信息", + "produces": [ + "application/json" + ], + "summary": "获取节点详情", + "parameters": [ + { + "type": "string", + "description": "节点 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.NodeResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "404": { + "description": "节点未找到", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/nodes/{id}/neighbors": { + "get": { + "description": "根据节点 ID 获取其所有邻居节点及关联边", + "produces": [ + "application/json" + ], + "summary": "获取节点邻居", + "parameters": [ + { + "type": "string", + "description": "节点 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.NeighborResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "404": { + "description": "节点未找到", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + }, + "/api/search": { + "get": { + "description": "根据关键词搜索知识图谱中的节点", + "produces": [ + "application/json" + ], + "summary": "搜索节点", + "parameters": [ + { + "type": "string", + "description": "搜索关键词", + "name": "q", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "成功", + "schema": { + "$ref": "#/definitions/models.SearchResponse" + } + }, + "400": { + "description": "请求错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + }, + "500": { + "description": "内部错误", + "schema": { + "$ref": "#/definitions/models.ErrorResponse" + } + } + } + } + } + }, + "definitions": { + "models.Edge": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "source": { + "type": "string" + }, + "style": { + "type": "object", + "additionalProperties": true + }, + "target": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "models.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "type": "string" + }, + "message": { + "type": "string" + } + } + }, + "models.GraphData": { + "type": "object", + "properties": { + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Edge" + } + }, + "nodes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + }, + "models.NeighborResponse": { + "type": "object", + "properties": { + "edges": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Edge" + } + }, + "nodes": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + }, + "models.Node": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "style": { + "type": "object", + "additionalProperties": true + }, + "type": { + "type": "string" + }, + "x": { + "type": "number" + }, + "y": { + "type": "number" + } + } + }, + "models.NodeResponse": { + "type": "object", + "properties": { + "id": { + "type": "string", + "example": "1" + }, + "label": { + "type": "string", + "example": "人工智能" + }, + "properties": { + "type": "object", + "additionalProperties": true + }, + "type": { + "type": "string", + "example": "概念" + } + } + }, + "models.SearchResponse": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "results": { + "type": "array", + "items": { + "$ref": "#/definitions/models.Node" + } + } + } + } + } +} \ No newline at end of file diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml new file mode 100644 index 0000000..1012c9b --- /dev/null +++ b/backend/docs/swagger.yaml @@ -0,0 +1,215 @@ +basePath: / +definitions: + models.Edge: + properties: + id: + type: string + label: + type: string + properties: + additionalProperties: true + type: object + source: + type: string + style: + additionalProperties: true + type: object + target: + type: string + type: + type: string + type: object + models.ErrorResponse: + properties: + error: + type: string + message: + type: string + type: object + models.GraphData: + properties: + edges: + items: + $ref: '#/definitions/models.Edge' + type: array + nodes: + items: + $ref: '#/definitions/models.Node' + type: array + type: object + models.NeighborResponse: + properties: + edges: + items: + $ref: '#/definitions/models.Edge' + type: array + nodes: + items: + $ref: '#/definitions/models.Node' + type: array + type: object + models.Node: + properties: + id: + type: string + label: + type: string + properties: + additionalProperties: true + type: object + style: + additionalProperties: true + type: object + type: + type: string + x: + type: number + "y": + type: number + type: object + models.NodeResponse: + properties: + id: + example: "1" + type: string + label: + example: 人工智能 + type: string + properties: + additionalProperties: true + type: object + type: + example: 概念 + type: string + type: object + models.SearchResponse: + properties: + count: + type: integer + results: + items: + $ref: '#/definitions/models.Node' + type: array + type: object +host: localhost:8080 +info: + contact: {} + description: 知识图谱后端服务,提供图数据查询、节点搜索等功能 + title: 知识图谱 API + version: 1.0.0 +paths: + /api/graph: + get: + description: 获取知识图谱的全部节点和边数据 + produces: + - application/json + responses: + "200": + description: 成功 + schema: + $ref: '#/definitions/models.GraphData' + "500": + description: 内部错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + summary: 获取图数据 + /api/graph/stats: + get: + description: 获取知识图谱的节点数、边数等统计信息 + produces: + - application/json + responses: + "200": + description: 成功 + schema: + additionalProperties: true + type: object + "500": + description: 内部错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + summary: 获取图统计信息 + /api/nodes/{id}: + get: + description: 根据节点 ID 获取知识图谱中的节点详细信息 + parameters: + - description: 节点 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 成功 + schema: + $ref: '#/definitions/models.NodeResponse' + "400": + description: 请求错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + "404": + description: 节点未找到 + schema: + $ref: '#/definitions/models.ErrorResponse' + "500": + description: 内部错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + summary: 获取节点详情 + /api/nodes/{id}/neighbors: + get: + description: 根据节点 ID 获取其所有邻居节点及关联边 + parameters: + - description: 节点 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 成功 + schema: + $ref: '#/definitions/models.NeighborResponse' + "400": + description: 请求错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + "404": + description: 节点未找到 + schema: + $ref: '#/definitions/models.ErrorResponse' + "500": + description: 内部错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + summary: 获取节点邻居 + /api/search: + get: + description: 根据关键词搜索知识图谱中的节点 + parameters: + - description: 搜索关键词 + in: query + name: q + required: true + type: string + produces: + - application/json + responses: + "200": + description: 成功 + schema: + $ref: '#/definitions/models.SearchResponse' + "400": + description: 请求错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + "500": + description: 内部错误 + schema: + $ref: '#/definitions/models.ErrorResponse' + summary: 搜索节点 +swagger: "2.0" diff --git a/backend/go.mod b/backend/go.mod index 6c61f38..1bdf6bc 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -7,23 +7,35 @@ require ( github.com/gin-gonic/gin v1.12.0 github.com/joho/godotenv v1.5.1 github.com/neo4j/neo4j-go-driver/v5 v5.28.4 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.1 + github.com/swaggo/swag v1.16.6 ) require ( + github.com/KyleBanks/depth v1.2.1 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/gopkg v0.1.4 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.1 // indirect github.com/cloudwego/base64x v0.1.6 // indirect github.com/gabriel-vasile/mimetype v1.4.13 // indirect github.com/gin-contrib/sse v1.1.1 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.30.2 // indirect github.com/goccy/go-json v0.10.6 // indirect github.com/goccy/go-yaml v1.19.2 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.3.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect + github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect @@ -35,8 +47,12 @@ require ( go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect golang.org/x/arch v0.25.0 // indirect golang.org/x/crypto v0.49.0 // indirect + golang.org/x/mod v0.33.0 // indirect golang.org/x/net v0.52.0 // indirect + golang.org/x/sync v0.20.0 // indirect golang.org/x/sys v0.42.0 // indirect golang.org/x/text v0.35.0 // indirect + golang.org/x/tools v0.42.0 // indirect google.golang.org/protobuf v1.36.11 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index dfe49c3..11c983d 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,3 +1,9 @@ +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/gopkg v0.1.4 h1:oZnQwnX82KAIWb7033bEwtxvTqXcYMxDBaQxo5JJHWM= github.com/bytedance/gopkg v0.1.4/go.mod h1:v1zWfPm21Fb+OsyXN2VAHdL6TBb2L88anLQgdyje6R4= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -6,6 +12,7 @@ github.com/bytedance/sonic/loader v0.5.1 h1:Ygpfa9zwRCCKSlrp5bBP/b/Xzc3VxsAW+5NI github.com/bytedance/sonic/loader v0.5.1/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -13,10 +20,22 @@ github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9 github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s= github.com/gin-contrib/cors v1.7.7 h1:Oh9joP463x7Mw72vhvJ61YQm8ODh9b04YR7vsOErD0Q= github.com/gin-contrib/cors v1.7.7/go.mod h1:K5tW0RkzJtWSiOdikXloy8VEZlgdVNpHNw8FpjUPNrE= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= +github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= github.com/gin-contrib/sse v1.1.1 h1:uGYpNwTacv5R68bSGMapo62iLTRa9l5zxGCps4hK6ko= github.com/gin-contrib/sse v1.1.1/go.mod h1:QXzuVkA0YO7o/gun03UI1Q+FTI8ZV/n5t03kIQAI89s= github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8= github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -34,12 +53,25 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -49,6 +81,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/neo4j/neo4j-go-driver/v5 v5.28.4 h1:7toxehVcYkZbyxV4W3Ib9VcnyRBQPucF+VwNNmtSXi4= github.com/neo4j/neo4j-go-driver/v5 v5.28.4/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pelletier/go-toml/v2 v2.3.0 h1:k59bC/lIZREW0/iVaQR8nDHxVq8OVlIzYCOJf421CaM= github.com/pelletier/go-toml/v2 v2.3.0/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -57,39 +90,92 @@ github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8= github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII= github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SAw= github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.1 h1:Ri06G4gc9N4t4k8hekMigJ9zKTFSlqj/9paAQCQs7cY= +github.com/swaggo/gin-swagger v1.6.1/go.mod h1:LQ+hJStHakCWRiK/YNYtJOu4mR2FP+pxLnILT/qNiTw= +github.com/swaggo/swag v1.16.6 h1:qBNcx53ZaX+M5dxVyTrgQ0PJ/ACK+NzhwcbieTt+9yI= +github.com/swaggo/swag v1.16.6/go.mod h1:ngP2etMK5a0P3QBizic5MEwpRmluJZPHjXcMoj4Xesg= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.3.1 h1:waO7eEiFDwidsBN6agj1vJQ4AG7lh2yqXyOXqhgQuyY= github.com/ugorji/go/codec v1.3.1/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF3xaE= go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0= go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y= go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU= golang.org/x/arch v0.25.0 h1:qnk6Ksugpi5Bz32947rkUgDt9/s5qvqDPl/gBKdMJLE= golang.org/x/arch v0.25.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= +golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= +golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= +golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/backend/handlers/graph_handler.go b/backend/handlers/graph_handler.go index aecf476..b427931 100644 --- a/backend/handlers/graph_handler.go +++ b/backend/handlers/graph_handler.go @@ -17,11 +17,23 @@ func NewGraphHandler(service services.GraphService) *GraphHandler { } } +// @Summary 获取图数据 +// @Description 获取知识图谱的全部节点和边数据 +// @Produce json +// @Success 200 {object} models.GraphData "成功" +// @Failure 500 {object} models.ErrorResponse "内部错误" +// @Router /api/graph [get] func (h *GraphHandler) GetGraphData(c *gin.Context) { data := h.service.GetGraphData() c.JSON(http.StatusOK, data) } +// @Summary 获取图统计信息 +// @Description 获取知识图谱的节点数、边数等统计信息 +// @Produce json +// @Success 200 {object} map[string]interface{} "成功" +// @Failure 500 {object} models.ErrorResponse "内部错误" +// @Router /api/graph/stats [get] func (h *GraphHandler) GetStats(c *gin.Context) { stats := h.service.GetStats() c.JSON(http.StatusOK, gin.H{ diff --git a/backend/handlers/node_handler.go b/backend/handlers/node_handler.go index 9d018c5..ff6dd89 100644 --- a/backend/handlers/node_handler.go +++ b/backend/handlers/node_handler.go @@ -17,6 +17,15 @@ func NewNodeHandler(service services.GraphService) *NodeHandler { } } +// @Summary 获取节点详情 +// @Description 根据节点 ID 获取知识图谱中的节点详细信息 +// @Produce json +// @Param id path string true "节点 ID" +// @Success 200 {object} models.NodeResponse "成功" +// @Failure 400 {object} models.ErrorResponse "请求错误" +// @Failure 404 {object} models.ErrorResponse "节点未找到" +// @Failure 500 {object} models.ErrorResponse "内部错误" +// @Router /api/nodes/{id} [get] func (h *NodeHandler) GetNodeByID(c *gin.Context) { nodeID := c.Param("id") if nodeID == "" { @@ -39,6 +48,15 @@ func (h *NodeHandler) GetNodeByID(c *gin.Context) { c.JSON(http.StatusOK, node) } +// @Summary 获取节点邻居 +// @Description 根据节点 ID 获取其所有邻居节点及关联边 +// @Produce json +// @Param id path string true "节点 ID" +// @Success 200 {object} models.NeighborResponse "成功" +// @Failure 400 {object} models.ErrorResponse "请求错误" +// @Failure 404 {object} models.ErrorResponse "节点未找到" +// @Failure 500 {object} models.ErrorResponse "内部错误" +// @Router /api/nodes/{id}/neighbors [get] func (h *NodeHandler) GetNeighbors(c *gin.Context) { nodeID := c.Param("id") if nodeID == "" { diff --git a/backend/handlers/search_handler.go b/backend/handlers/search_handler.go index debe3d9..00a919f 100644 --- a/backend/handlers/search_handler.go +++ b/backend/handlers/search_handler.go @@ -17,6 +17,14 @@ func NewSearchHandler(service services.GraphService) *SearchHandler { } } +// @Summary 搜索节点 +// @Description 根据关键词搜索知识图谱中的节点 +// @Produce json +// @Param q query string true "搜索关键词" +// @Success 200 {object} models.SearchResponse "成功" +// @Failure 400 {object} models.ErrorResponse "请求错误" +// @Failure 500 {object} models.ErrorResponse "内部错误" +// @Router /api/search [get] func (h *SearchHandler) SearchNodes(c *gin.Context) { query := c.Query("q") if query == "" { diff --git a/backend/main.go b/backend/main.go index c1a9a86..029e696 100644 --- a/backend/main.go +++ b/backend/main.go @@ -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",