package router import ( "github.com/iris-contrib/middleware/cors" "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/mvc" "xps/bootstrap" "xps/service" "xps/web/controllers" "xps/web/middleware" ) func Configure(b *bootstrap.Bootstrapper) { crs := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"PUT", "PATCH", "GET", "POST", "OPTIONS", "DELETE"}, AllowedHeaders: []string{"*"}, ExposedHeaders: []string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization"}, AllowCredentials: true, }) // Static Resource b.HandleDir("/", "./public") // Login loginService := service.NewLoginService() loginApp := mvc.New(b.Party("/", crs).AllowMethods(iris.MethodOptions)) loginApp.Register(loginService) loginApp.Handle(new(controllers.LoginController)) // role sysParty := b.Party("/sys", crs).AllowMethods(iris.MethodOptions) { sysParty.Use(middleware.AuthToken) // Role roleService := service.NewRoleService() roleApp := mvc.New(sysParty.Party("/role")) roleApp.Register(roleService) roleApp.Handle(new(controllers.RoleController)) } // Company Profile companyParty := b.Party("/company", crs).AllowMethods(iris.MethodOptions) { companyParty.Use(middleware.AuthToken) companyProfileService := service.NewCompanyProfileService() companyProfileApp := mvc.New(companyParty.Party("/profile")) companyProfileApp.Register(companyProfileService) companyProfileApp.Handle(new(controllers.CompanyProfileController)) } // Group groupParty := b.Party("/group", crs).AllowMethods(iris.MethodOptions) { groupParty.Use(middleware.AuthToken) groupService := service.NewGroupService() groupApp := mvc.New(groupParty.Party("")) groupApp.Register(groupService) groupApp.Handle(new(controllers.GroupController)) } // User userParty := b.Party("/user", crs).AllowMethods(iris.MethodOptions) { userParty.Use(middleware.AuthToken) // user userService := service.NewUserService() userApp := mvc.New(userParty.Party("")) userApp.Register(userService) userApp.Handle(new(controllers.UserController)) } // Position positionParty := b.Party("/position", crs).AllowMethods(iris.MethodOptions) { positionParty.Use(middleware.AuthToken) positionService := service.NewPositionService() positionApp := mvc.New(positionParty.Party("")) positionApp.Register(positionService) positionApp.Handle(new(controllers.PositionController)) } // GroupCatParty GroupCatParty := b.Party("/group", crs).AllowMethods(iris.MethodOptions) { GroupCatParty.Use(middleware.AuthToken) groupCatService := service.NewGroupCatService() groupCatApp := mvc.New(GroupCatParty.Party("/cat")) groupCatApp.Register(groupCatService) groupCatApp.Handle(new(controllers.GroupCatController)) } // App appParty := b.Party("/app", crs).AllowMethods(iris.MethodOptions) { appParty.Use(middleware.AuthToken) appService := service.NewAppService() appApp := mvc.New(appParty.Party("")) appApp.Register(appService) appApp.Handle(new(controllers.AppController)) appCatService := service.NewAppCatService() appCatApp := mvc.New(appParty.Party("/cat")) appCatApp.Register(appCatService) appCatApp.Handle(new(controllers.AppCatController)) appPermitService := service.NewAppPermitService() appPermitApp := mvc.New(appParty.Party("/permit")) appPermitApp.Register(appPermitService) appPermitApp.Handle(new(controllers.AppPermitController)) } // TaskCat taskCatParty := b.Party("/task", crs).AllowMethods(iris.MethodOptions) { taskCatParty.Use(middleware.AuthToken) taskCatService := service.NewTaskCatService() taskCatApp := mvc.New(taskCatParty.Party("/cat")) taskCatApp.Register(taskCatService) taskCatApp.Handle(new(controllers.TaskCatController)) } // EntCat entCatParty := b.Party("/ent", crs).AllowMethods(iris.MethodOptions) { entCatParty.Use(middleware.AuthToken) entCatService := service.NewEntCatService() entCatApp := mvc.New(entCatParty.Party("/cat")) entCatApp.Register(entCatService) entCatApp.Handle(new(controllers.EntCatController)) } // PartnerCat partnerCatParty := b.Party("/partner", crs).AllowMethods(iris.MethodOptions) { partnerCatParty.Use(middleware.AuthToken) partnerCatService := service.NewPartnerCatService() partnerCatApp := mvc.New(partnerCatParty.Party("/cat")) partnerCatApp.Register(partnerCatService) partnerCatApp.Handle(new(controllers.PartnerCatController)) } // Model modelParty := b.Party("/model", crs).AllowMethods(iris.MethodOptions) { modelParty.Use(middleware.AuthToken) modelService := service.NewModelService() modelApp := mvc.New(modelParty.Party("")) modelApp.Register(modelService) modelApp.Handle(new(controllers.ModelController)) objectService := service.NewObjectService() objectApp := mvc.New(modelParty.Party("/object")) objectApp.Register(objectService) objectApp.Handle(new(controllers.ObjectController)) objectAttrService := service.NewObjectAttrService() objectAttrApp := mvc.New(modelParty.Party("/object/attribute")) objectAttrApp.Register(objectAttrService) objectAttrApp.Handle(new(controllers.ObjectAttrController)) } // DaaS daasParty := b.Party("/daas", crs).AllowMethods(iris.MethodOptions) { daasParty.Use(middleware.AuthToken) dbTypeService := service.NewDbTypeService() dbTypeApp := mvc.New(daasParty.Party("/dbType")) dbTypeApp.Register(dbTypeService) dbTypeApp.Handle(new(controllers.DbTypeController)) } // PaaS paasParty := b.Party("/paas", crs).AllowMethods(iris.MethodOptions) { paasParty.Use(middleware.AuthToken) moduleService := service.NewModuleService() moduleApp := mvc.New(paasParty.Party("/module")) moduleApp.Register(moduleService) moduleApp.Handle(new(controllers.ModuleController)) apiService := service.NewApiService() apiApp := mvc.New(paasParty.Party("/api")) apiApp.Register(apiService) apiApp.Handle(new(controllers.ApiController)) reqService := service.NewApiReqService() reqApp := mvc.New(paasParty.Party("/api/request")) reqApp.Register(reqService) reqApp.Handle(new(controllers.ApiReqController)) atuService := service.NewApiTransUnitService() apiAtuApp := mvc.New(paasParty.Party("/api/atu")) apiAtuApp.Register(atuService) apiAtuApp.Handle(new(controllers.ApiTransUnitController)) } // x xParty := b.Party("/x", crs).AllowMethods(iris.MethodOptions) { xParty.Use(middleware.AuthToken) apiGatewayService := service.NewApiGatewayService() apiGatewayApp := mvc.New(xParty.Party("")) apiGatewayApp.Register(apiGatewayService) apiGatewayApp.Handle(new(controllers.ApiGatewayController)) } }