Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "net/http"
  4. "git.x2erp.com/qdy/go-base/bootstraps"
  5. "git.x2erp.com/qdy/go-base/middleware"
  6. "git.x2erp.com/qdy/go-db/factory/database"
  7. "git.x2erp.com/qdy/go-db/myhandle"
  8. "git.x2erp.com/qdy/go-svc-agent/functions"
  9. "go-micro.dev/v4/web"
  10. )
  11. var (
  12. serviceName = "svc-agent"
  13. serviceVersion = "1.0.0"
  14. )
  15. func main() {
  16. // 创建服务启动器
  17. bootstrapper := bootstraps.NewServiceBootstrapper(serviceName, serviceVersion)
  18. //加载配置
  19. bootstrapper.InitConfig()
  20. //构建数据库工厂
  21. bootstrapper.InitDatabase()
  22. //dbFactory := bootstrapper.DbFactory
  23. // 启动服务,传入路由注册函数
  24. bootstrapper.Run(registerRoutes)
  25. }
  26. // 注册所有路由
  27. func registerRoutes(webService web.Service, dbFactory *database.DBFactory) {
  28. // 查询接口 - JSON
  29. webService.Handle("/api/query/json", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  30. myhandle.QueryHandlerJson(w, r, dbFactory, functions.QueryToJSON)
  31. })))
  32. // 查询接口 - CSV
  33. webService.Handle("/api/query/csv", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  34. myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryToCSV)
  35. })))
  36. // 查询接口 - CSV with positional params
  37. webService.Handle("/api/query/csv/param", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  38. myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryPositionalToCSV)
  39. })))
  40. }