| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package main
-
- import (
- "git.x2erp.com/qdy/go-db/factory/database"
-
- "git.x2erp.com/qdy/go-base/config"
- "git.x2erp.com/qdy/go-base/consul"
- "git.x2erp.com/qdy/go-base/container"
- "git.x2erp.com/qdy/go-base/graceful"
- "git.x2erp.com/qdy/go-base/logger"
-
- "git.x2erp.com/qdy/go-base/webx"
- "git.x2erp.com/qdy/go-base/webx/health"
- "git.x2erp.com/qdy/go-base/webx/router"
- )
-
- var (
- appName = "svc-mercury"
- appVersion = "1"
- )
-
- // 定义结构体
- type CreateUserRequest struct {
- Name string `json:"name"`
- Email string `json:"email"`
- Age int `json:"age"`
- }
-
- type UserResponse struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Email string `json:"email"`
- Data []map[string]interface{}
- }
-
- func main() {
-
- //0.日志
- //logger.InitBootLog()
- logBootFactory := logger.InitBootLog()
-
- //1.获取配置文件
- cfg := config.GetConfig()
- cfg.SetAppName(appName)
- cfg.SetAppVersion(appVersion)
-
- //2.创建关闭容器
- ctr := container.NewContainer(cfg)
-
- //注册日志,实现自动关闭
- container.Reg(ctr, logBootFactory)
-
- //3.创建数据库工厂--如果需求
- dbFactory := container.Create(ctr, database.CreateDBFactory)
-
- // 赋值认证中间件参数
- //middleware.JWTAuthMiddlewareInit(cfg)
-
- //测试数据库连接
- dbFactory.TestConnection()
-
- //得到webservice服务工厂
- webxFactory := webx.GetWebServiceFactory()
-
- //建立hhtpService服务
- webServcie, _ := webxFactory.CreateService(cfg.GetServiceConfig())
-
- //建立路由-api
- routerService := router.NewWebService(webServcie.GetRouter())
-
- //注册路由--api
- //registerDorisRouter(routerService, dbFactory)
-
- // 注册健康检查-api
- health.RegisterConsulHealthCheck(routerService)
-
- //启动服务
- webServcie.Run()
-
- //启用运行日志
- container.Create(ctr, logger.InitRuntimeLogger)
-
- //注册到注册中心
- container.Create(ctr, consul.Register)
- //等待关闭
- //webServcie.WaitForServiceShutdown(ctr)
-
- //启动服务
- webServcie.Run()
-
- //等待关闭
- graceful.WaitForShutdown(cfg.GetServiceConfig().ServiceName, ctr, webServcie.GetServer())
-
- }
|