func cloneConfigsFromApp(from, to, aux_info, userKey string) (*models.App, []*models.Config, error) { memConfMux.RLock() fromApp := memConfAppsByName[from] memConfMux.RUnlock() fromConfigs, err := models.GetConfigsByAppKey(nil, fromApp.Key) if err != nil { return nil, nil, err } app := &models.App{ Key: utils.GenerateKey(), Name: to, UserKey: userKey, AuxInfo: aux_info, CreatedUTC: utils.GetNowSecond(), Type: fromApp.Type, } for _, config := range fromConfigs { config.Key = utils.GenerateKey() config.CreatorKey = app.UserKey config.AppKey = app.Key config.CreatedUTC = app.CreatedUTC } if err := cloneConfigs(app, fromConfigs, userKey); err != nil { return nil, nil, err } return app, fromConfigs, nil }
func GetConfigs(c *gin.Context) { appKey := c.Param("app_key") configs, err := models.GetConfigsByAppKey(nil, appKey) if err != nil { Error(c, SERVER_ERROR, err.Error()) return } memConfMux.RLock() for _, config := range configs { config.CreatorName = memConfUsers[config.CreatorKey].Name config.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, config.LastUpdateId) config.LastUpdateInfo.UserName = memConfUsers[config.LastUpdateInfo.UserKey].Name } memConfMux.RUnlock() Success(c, configs) }