更新
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user