74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package neo4j
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/gin-contrib/cors"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"knowledge-graph-backend/handlers"
|
|
"knowledge-graph-backend/services"
|
|
)
|
|
|
|
const (
|
|
PORT = "3001"
|
|
DATA_FILE = "data.json"
|
|
)
|
|
|
|
func test() {
|
|
|
|
dataService, err := services.NewDataService(DATA_FILE)
|
|
if err != nil {
|
|
log.Fatalf("Failed to initialize data service: %v", err)
|
|
}
|
|
|
|
graphHandler := handlers.NewGraphHandler(dataService)
|
|
searchHandler := handlers.NewSearchHandler(dataService)
|
|
nodeHandler := handlers.NewNodeHandler(dataService)
|
|
|
|
router := gin.Default()
|
|
|
|
router.Use(cors.New(cors.Config{
|
|
AllowOrigins: []string{"http://localhost:5173", "http://localhost:3000"},
|
|
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization", "Accept"},
|
|
ExposeHeaders: []string{"Content-Length", "Content-Type"},
|
|
AllowCredentials: true,
|
|
MaxAge: 12 * 3600,
|
|
}))
|
|
|
|
router.GET("/health", func(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "ok",
|
|
"message": "Knowledge Graph API is running",
|
|
"version": "1.0.0",
|
|
})
|
|
})
|
|
|
|
api := router.Group("/api")
|
|
{
|
|
api.GET("/graph", graphHandler.GetGraphData)
|
|
api.GET("/graph/stats", graphHandler.GetStats)
|
|
|
|
api.GET("/search", searchHandler.SearchNodes)
|
|
|
|
api.GET("/nodes/:id", nodeHandler.GetNodeByID)
|
|
api.GET("/nodes/:id/neighbors", nodeHandler.GetNeighbors)
|
|
}
|
|
|
|
log.Println("Knowledge Graph API Server running on http://localhost:" + PORT)
|
|
log.Println("Data file loaded from: " + DATA_FILE)
|
|
log.Println("Available endpoints:")
|
|
log.Println(" GET /health - Health check")
|
|
log.Println(" GET /api/graph - Get all graph data")
|
|
log.Println(" GET /api/graph/stats - Get graph statistics")
|
|
log.Println(" GET /api/search?q=query - Search nodes")
|
|
log.Println(" GET /api/nodes/:id - Get node by ID")
|
|
log.Println(" GET /api/nodes/:id/neighbors - Get node neighbors")
|
|
|
|
if err := router.Run(":" + PORT); err != nil {
|
|
log.Fatalf("Failed to start server: %v", err)
|
|
}
|
|
}
|