2024-10-19 22:02:19 +08:00
|
|
|
|
package http
|
|
|
|
|
|
2024-10-23 17:00:42 +08:00
|
|
|
|
import (
|
2024-10-31 16:56:03 +08:00
|
|
|
|
"github.com/Superdanda/hade/app/infrastructure"
|
2024-10-27 17:54:21 +08:00
|
|
|
|
"github.com/Superdanda/hade/app/provider/database_connect"
|
2024-10-23 17:00:42 +08:00
|
|
|
|
"github.com/Superdanda/hade/framework"
|
|
|
|
|
"github.com/Superdanda/hade/framework/gin"
|
|
|
|
|
)
|
2024-10-19 22:02:19 +08:00
|
|
|
|
|
|
|
|
|
// NewHttpEngine 创建了一个绑定了路由的Web引擎
|
2024-10-23 17:00:42 +08:00
|
|
|
|
func NewHttpEngine(container *framework.HadeContainer) (*gin.Engine, error) {
|
2024-10-19 22:02:19 +08:00
|
|
|
|
// 设置为Release,为的是默认在启动中不输出调试信息
|
|
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
|
// 默认启动一个Web引擎
|
|
|
|
|
r := gin.Default()
|
2024-10-23 17:00:42 +08:00
|
|
|
|
r.SetContainer(container)
|
2024-10-31 16:56:03 +08:00
|
|
|
|
|
2024-10-19 22:02:19 +08:00
|
|
|
|
// 返回绑定路由后的Web引擎
|
2024-10-27 17:54:21 +08:00
|
|
|
|
|
|
|
|
|
// 对业务模型进行注册,通过注册名获取业务模型类型信息
|
|
|
|
|
TypeRegister(container)
|
|
|
|
|
|
|
|
|
|
//绑定服务
|
|
|
|
|
container.Bind(&database_connect.DatabaseConnectProvider{})
|
|
|
|
|
|
2024-10-31 16:56:03 +08:00
|
|
|
|
//注册 infrastructure 包的实例
|
|
|
|
|
infrastructure.NewOrmRepositoryAndRegister(container)
|
|
|
|
|
|
|
|
|
|
// 业务绑定路由操作
|
|
|
|
|
Routes(r)
|
2024-10-19 22:02:19 +08:00
|
|
|
|
return r, nil
|
|
|
|
|
}
|