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 sys := b.Party("/sys", crs).AllowMethods(iris.MethodOptions) { sys.Use(middleware.AuthToken) // Role roleService := service.NewRoleService() roleApp := mvc.New(sys.Party("/role")) roleApp.Register(roleService) roleApp.Handle(new(controllers.RoleController)) } // Company Profile company := b.Party("/company", crs).AllowMethods(iris.MethodOptions) { company.Use(middleware.AuthToken) companyProfileService := service.NewCompanyProfileService() companyProfileApp := mvc.New(company.Party("/profile")) companyProfileApp.Register(companyProfileService) companyProfileApp.Handle(new(controllers.CompanyProfileController)) } // Group group := b.Party("/group", crs).AllowMethods(iris.MethodOptions) { group.Use(middleware.AuthToken) groupService := service.NewGroupService() groupApp := mvc.New(group.Party("")) groupApp.Register(groupService) groupApp.Handle(new(controllers.GroupController)) } // User user := b.Party("/user", crs).AllowMethods(iris.MethodOptions) { user.Use(middleware.AuthToken) // user userService := service.NewUserService() userApp := mvc.New(user.Party("")) userApp.Register(userService) userApp.Handle(new(controllers.UserController)) } // Position position := b.Party("/position", crs).AllowMethods(iris.MethodOptions) { position.Use(middleware.AuthToken) positionService := service.NewPositionService() positionApp := mvc.New(position.Party("")) positionApp.Register(positionService) positionApp.Handle(new(controllers.PositionController)) } // GroupCat groupCat := b.Party("/group", crs).AllowMethods(iris.MethodOptions) { groupCat.Use(middleware.AuthToken) groupCatService := service.NewGroupCatService() groupCatApp := mvc.New(groupCat.Party("/cat")) groupCatApp.Register(groupCatService) groupCatApp.Handle(new(controllers.GroupCatController)) } // App app := b.Party("/app", crs).AllowMethods(iris.MethodOptions) { app.Use(middleware.AuthToken) appService := service.NewAppService() appApp := mvc.New(app.Party("")) appApp.Register(appService) appApp.Handle(new(controllers.AppController)) appCatService := service.NewAppCatService() appCatApp := mvc.New(app.Party("/cat")) appCatApp.Register(appCatService) appCatApp.Handle(new(controllers.AppCatController)) appPermitService := service.NewAppPermitService() appPermitApp := mvc.New(app.Party("/permit")) appPermitApp.Register(appPermitService) appPermitApp.Handle(new(controllers.AppPermitController)) } // TaskCat taskCat := b.Party("/task", crs).AllowMethods(iris.MethodOptions) { taskCat.Use(middleware.AuthToken) taskCatService := service.NewTaskCatService() taskCatApp := mvc.New(taskCat.Party("/cat")) taskCatApp.Register(taskCatService) taskCatApp.Handle(new(controllers.TaskCatController)) } // EntCat entCat := b.Party("/ent", crs).AllowMethods(iris.MethodOptions) { entCat.Use(middleware.AuthToken) entCatService := service.NewEntCatService() entCatApp := mvc.New(entCat.Party("/cat")) entCatApp.Register(entCatService) entCatApp.Handle(new(controllers.EntCatController)) } // PartnerCat partnerCat := b.Party("/partner", crs).AllowMethods(iris.MethodOptions) { partnerCat.Use(middleware.AuthToken) partnerCatService := service.NewPartnerCatService() partnerCatApp := mvc.New(partnerCat.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)) } }