27 lines
		
	
	
		
			626 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			626 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						||
 | 
						||
import (
 | 
						||
	"server/models"
 | 
						||
	_ "server/models" // 确保菜单模型被正确导入
 | 
						||
	_ "server/routers"
 | 
						||
 | 
						||
	beego "github.com/beego/beego/v2/server/web"
 | 
						||
	"github.com/beego/beego/v2/server/web/context"
 | 
						||
)
 | 
						||
 | 
						||
func main() {
 | 
						||
	// 初始化数据库
 | 
						||
	models.Init()
 | 
						||
 | 
						||
	// CORS配置已移至router.go中统一管理
 | 
						||
	// 确保请求体被正确读取(包括 POST、PUT、PATCH)
 | 
						||
	beego.InsertFilter("*", beego.BeforeRouter, func(ctx *context.Context) {
 | 
						||
		method := ctx.Input.Method()
 | 
						||
		if method == "PUT" || method == "POST" || method == "PATCH" {
 | 
						||
			ctx.Input.CopyBody(1024 * 1024) // 1MB 缓冲区
 | 
						||
		}
 | 
						||
	})
 | 
						||
 | 
						||
	beego.Run()
 | 
						||
}
 |