| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package main
-
- import (
- "net/http"
-
- "git.x2erp.com/qdy/go-base/bootstraps"
- "git.x2erp.com/qdy/go-base/middleware"
- "git.x2erp.com/qdy/go-db/factory/database"
- "git.x2erp.com/qdy/go-db/myhandle"
- "git.x2erp.com/qdy/go-svc-agent/functions"
- "go-micro.dev/v4/web"
- )
-
- var (
- serviceName = "svc-agent"
- serviceVersion = "1.0.0"
- )
-
- func main() {
-
- // 创建服务启动器
- bootstrapper := bootstraps.NewServiceBootstrapper(serviceName, serviceVersion)
-
- //加载配置
- bootstrapper.InitConfig()
-
- //构建数据库工厂
- bootstrapper.InitDatabase()
-
- //dbFactory := bootstrapper.DbFactory
-
- // 启动服务,传入路由注册函数
- bootstrapper.Run(registerRoutes)
-
- }
-
- // 注册所有路由
- func registerRoutes(webService web.Service, dbFactory *database.DBFactory) {
-
- // 查询接口 - JSON
- webService.Handle("/api/query/json", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- myhandle.QueryHandlerJson(w, r, dbFactory, functions.QueryToJSON)
- })))
-
- // 查询接口 - CSV
- webService.Handle("/api/query/csv", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryToCSV)
- })))
-
- // 查询接口 - CSV with positional params
- webService.Handle("/api/query/csv/param", middleware.JWTAuthMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- myhandle.QueryHandlerBytes(w, r, dbFactory, functions.QueryPositionalToCSV)
- })))
- }
|