This commit is contained in:
2026-04-26 21:26:15 +08:00
parent 95bf0c3342
commit 7a7e28684c
10 changed files with 390 additions and 193 deletions
+30
View File
@@ -0,0 +1,30 @@
package router
import (
"github.com/gin-gonic/gin"
"level_go/internal/api"
)
func NewRouter(commonApi *api.CommonHandler, stockApi *api.StockHandler) *gin.Engine {
r := gin.Default()
// 跨域中间件 (根据需要开启)
r.Use(func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
})
v1 := r.Group("/api/v1")
{
v1.GET("/common/trade-calendar", commonApi.GetTradeCalendar)
v1.POST("/stock/analyze", stockApi.Analyze)
v1.GET("/stock/kline/:code", stockApi.GetKlineData)
}
return r
}