func GetConfigByKey(c *gin.Context) { memConfMux.RLock() configPtr := memConfRawConfigs[c.Param("config_key")] memConfMux.RUnlock() if configPtr != nil { config := *configPtr config.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, config.LastUpdateId) memConfMux.RLock() config.LastUpdateInfo.UserName = memConfUsers[config.LastUpdateInfo.UserKey].Name memConfMux.RUnlock() Success(c, config) } else { Error(c, BAD_REQUEST, "config not exists") } }
func GetApp(c *gin.Context) { memConfMux.RLock() app := memConfApps[c.Param("app_key")] memConfMux.RUnlock() if app == nil { Success(c, nil) return } returnApp := *app returnApp.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, returnApp.LastUpdateId) memConfMux.RLock() returnApp.UserName = memConfUsers[returnApp.UserKey].Name memConfMux.RUnlock() Success(c, &returnApp) }
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) }
func SearchApps(c *gin.Context) { apps, err := searchApps(c.Query("q"), 0) if err != nil { Error(c, SERVER_ERROR, err.Error()) return } memConfMux.RLock() for _, app := range apps { app.UserName = memConfUsers[app.UserKey].Name app.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, app.LastUpdateId) if app.LastUpdateInfo != nil { app.LastUpdateInfo.UserName = memConfUsers[app.LastUpdateInfo.UserKey].Name } } memConfMux.RUnlock() Success(c, apps) }
func GetApps(c *gin.Context) { userKey := c.Param("user_key") apps, err := models.GetAppsByUserKey(nil, userKey) if err != nil { Error(c, SERVER_ERROR, err.Error()) return } memConfMux.RLock() for _, app := range apps { app.UserName = memConfUsers[app.UserKey].Name app.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, app.LastUpdateId) if app.LastUpdateInfo != nil { app.LastUpdateInfo.UserName = memConfUsers[app.LastUpdateInfo.UserKey].Name } } memConfMux.RUnlock() Success(c, apps) }
func GetAllApps(c *gin.Context) { page, err := strconv.Atoi(c.Param("page")) if err != nil { Error(c, BAD_REQUEST, "page not number") return } count, err := strconv.Atoi(c.Param("count")) if err != nil { Error(c, BAD_REQUEST, "count not number") return } apps, err := models.GetAllAppsPage(nil, page, count) if err != nil { Error(c, SERVER_ERROR, err.Error()) return } totalCount, err := models.GetAppCount(nil) if err != nil { Error(c, SERVER_ERROR, err.Error()) return } memConfMux.RLock() for _, app := range apps { app.UserName = memConfUsers[app.UserKey].Name app.LastUpdateInfo, _ = models.GetConfigUpdateHistoryById(nil, app.LastUpdateId) if app.LastUpdateInfo != nil { app.LastUpdateInfo.UserName = memConfUsers[app.LastUpdateInfo.UserKey].Name } } memConfMux.RUnlock() Success(c, map[string]interface{}{ "total_count": totalCount, "list": apps, }) }