설명 없음
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.

main.go 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. defer bootstrapper.CleanupDatabase()
  23. //dbFactory := bootstrapper.DbFactory
  24. // 启动服务,传入路由注册函数
  25. bootstrapper.Run(registerRoutes)
  26. }
  27. // 注册所有路由
  28. func registerRoutes(webService web.Service, dbFactory *database.DBFactory) {
  29. // 查询接口 - JSON
  30. webService.Handle("/api/query/json", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  31. myhandle.QueryHandlerJson(w, r, dbFactory, functions.QueryToJSON)
  32. })))
  33. // 查询接口 - CSV
  34. webService.Handle("/api/query/csv", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  35. myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryToCSV)
  36. })))
  37. // 查询接口 - CSV with positional params
  38. webService.Handle("/api/query/csv/param", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  39. myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryPositionalToCSV)
  40. })))
  41. }