| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package main
-
- import (
- "git.x2erp.com/qdy/go-db/factory/database"
- "git.x2erp.com/qdy/go-svc-agent/functions"
-
- "git.x2erp.com/qdy/go-base/auth"
- "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/ctx"
- "git.x2erp.com/qdy/go-base/graceful"
- "git.x2erp.com/qdy/go-base/logger"
-
- "git.x2erp.com/qdy/go-base/model/request/dorisreq"
- "git.x2erp.com/qdy/go-base/model/response"
-
- "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-core"
- appVersion = "1"
- )
-
- 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.创建数据库工厂--如果需求
- dbsFactory := container.Create(ctr, database.CreateDBSFactory)
-
- // 赋值认证中间件参数
- //authJWTAuthMiddlewareInit(cfg)
-
- //得到webservice服务工厂
- webxFactory := webx.GetWebServiceFactory()
-
- //建立hhtpService服务
- webServcie, _ := webxFactory.CreateService(cfg.GetServiceConfig())
-
- //建立路由-api
- routerService := router.NewWebService(webServcie.GetRouter())
-
- //注册路由--api
- registerDefaultRouter(routerService, dbsFactory)
-
- // 注册健康检查-api
- health.RegisterConsulHealthCheck(routerService)
-
- //启动服务
- webServcie.Run()
-
- //启用运行日志
- container.Create(ctr, logger.InitRuntimeLogger)
-
- //注册到注册中心
- container.Create(ctr, consul.Register)
- //等待关闭
- graceful.WaitForShutdown(cfg.GetServiceConfig().ServiceName, ctr, webServcie.GetServer())
- }
-
- func registerDefaultRouter(ws *router.RouterService, dbsFactory *database.DBSFactory) {
-
- ws.POST("/api/query/json/{dbname}",
- func(dbname string, req dorisreq.QueryRequest, reqCtx *ctx.RequestContext) (*response.QueryResult[[]map[string]interface{}], error) {
-
- return functions.QueryToJSON(dbname, dbsFactory, req, reqCtx)
- },
- ).Use(auth.TokenAuth).Register()
-
- ws.POST("/api/query/csv/{dbname}",
- func(dbname string, req dorisreq.QueryRequest, reqCtx *ctx.RequestContext) ([]byte, error) {
-
- return functions.QueryToCSV(dbname, dbsFactory, req, reqCtx)
- },
- ).Use(auth.TokenAuth).Register()
-
- ws.POST("/api/query/csv/param/{dbname}",
- func(dbname string, req dorisreq.QueryRequest, reqCtx *ctx.RequestContext) ([]byte, error) {
-
- return functions.QueryPositionalToCSV(dbname, dbsFactory, req, reqCtx)
-
- },
- ).Use(auth.TokenAuth).Register()
-
- }
|