(cmsConfig *resource.CmsConfig, transaction *sqlx.Tx, cruds map[string]*resource.DbResource, authMiddleware *auth.AuthMiddleware, rateConfig RateConfig, max_connections int, olricClient *olric.EmbeddedClient)
| 25 | ) |
| 26 | |
| 27 | func CreateSubSites(cmsConfig *resource.CmsConfig, transaction *sqlx.Tx, |
| 28 | cruds map[string]*resource.DbResource, authMiddleware *auth.AuthMiddleware, |
| 29 | rateConfig RateConfig, max_connections int, olricClient *olric.EmbeddedClient) (hostswitch.HostSwitch, map[daptinid.DaptinReferenceId]*assetcachepojo.AssetFolderCache) { |
| 30 | |
| 31 | hs := hostswitch.HostSwitch{ |
| 32 | AdministratorGroupId: cruds["usergroup"].AdministratorGroupId, |
| 33 | } |
| 34 | subsiteCacheFolders := make(map[daptinid.DaptinReferenceId]*assetcachepojo.AssetFolderCache) |
| 35 | hs.HandlerMap = make(map[string]*gin.Engine) |
| 36 | hs.SiteMap = make(map[string]subsite.SubSite) |
| 37 | hs.AuthMiddleware = authMiddleware |
| 38 | |
| 39 | // Initialize the subsite cache with Olric client |
| 40 | if olricClient != nil { |
| 41 | err := InitSubsiteCache(olricClient) |
| 42 | if err != nil { |
| 43 | log.Errorf("Failed to initialize subsite cache: %v", err) |
| 44 | } else { |
| 45 | log.Infof("Subsite cache initialized with Olric") |
| 46 | } |
| 47 | } else { |
| 48 | log.Warnf("Olric client is nil, subsite cache will not be available") |
| 49 | } |
| 50 | |
| 51 | //log.Printf("Cruds before making sub sits: %v", cruds) |
| 52 | sites, err := subsite.GetAllSites(cruds["site"], transaction) |
| 53 | if err != nil { |
| 54 | log.Printf("Failed to get all sites 117: %v", err) |
| 55 | } |
| 56 | stores, err := cloud_store.GetAllCloudStores(cruds["cloud_store"], transaction) |
| 57 | if err != nil { |
| 58 | log.Printf("Failed to get all cloudstores 121: %v", err) |
| 59 | } |
| 60 | cloudStoreMap := make(map[int64]rootpojo.CloudStore) |
| 61 | |
| 62 | adminEmailId := cruds[resource.USER_ACCOUNT_TABLE_NAME].GetAdminEmailId(transaction) |
| 63 | log.Printf("Admin email id: %s", adminEmailId) |
| 64 | |
| 65 | for _, store := range stores { |
| 66 | cloudStoreMap[store.Id] = store |
| 67 | } |
| 68 | |
| 69 | siteMap := make(map[string]resource.SubSiteInformation) |
| 70 | |
| 71 | if err != nil { |
| 72 | log.Errorf("Failed to load sites from database: %v", err) |
| 73 | return hs, subsiteCacheFolders |
| 74 | } |
| 75 | |
| 76 | //max_connections, err := configStore.GetConfigIntValueFor("limit.max_connections", "backend") |
| 77 | //rate_limit, err := configStore.GetConfigIntValueFor("limit.rate", "backend") |
| 78 | |
| 79 | rateLimiter := limit2.NewRateLimiter(func(c *gin.Context) string { |
| 80 | requestPath := c.Request.Host + "/" + strings.Split(c.Request.RequestURI, "?")[0] |
| 81 | return c.ClientIP() + requestPath // limit rate by client ip |
| 82 | }, func(c *gin.Context) (*rate.Limiter, time.Duration) { |
| 83 | requestPath := c.Request.Host + "/" + strings.Split(c.Request.RequestURI, "?")[0] |
| 84 | limitValue, ok := rateConfig.limits[requestPath] |
no test coverage detected