fix: 前向兼容性 | for range pointer issue
This commit is contained in:
		
							parent
							
								
									548d25c9a6
								
							
						
					
					
						commit
						2ccb8f3477
					
				@ -239,7 +239,7 @@ func (ma *memberAPI) addOrEditMonitor(c *gin.Context) {
 | 
			
		||||
		err = m.InitSkipServers()
 | 
			
		||||
	}
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		// 旧版本服务监控可能不存在通知组 为其添加默认的通知组
 | 
			
		||||
		// 保证NotificationTag不为空
 | 
			
		||||
		if m.NotificationTag == "" {
 | 
			
		||||
			m.NotificationTag = "default"
 | 
			
		||||
		}
 | 
			
		||||
@ -292,6 +292,10 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	tx := singleton.DB.Begin()
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		// 保证NotificationTag不为空
 | 
			
		||||
		if cr.NotificationTag == "" {
 | 
			
		||||
			cr.NotificationTag = "default"
 | 
			
		||||
		}
 | 
			
		||||
		if cf.ID == 0 {
 | 
			
		||||
			err = tx.Create(&cr).Error
 | 
			
		||||
		} else {
 | 
			
		||||
@ -483,6 +487,10 @@ func (ma *memberAPI) addOrEditAlertRule(c *gin.Context) {
 | 
			
		||||
		enable := arf.Enable == "on"
 | 
			
		||||
		r.Enable = &enable
 | 
			
		||||
		r.ID = arf.ID
 | 
			
		||||
		//保证NotificationTag不为空
 | 
			
		||||
		if r.NotificationTag == "" {
 | 
			
		||||
			r.NotificationTag = "default"
 | 
			
		||||
		}
 | 
			
		||||
		if r.ID == 0 {
 | 
			
		||||
			err = singleton.DB.Create(&r).Error
 | 
			
		||||
		} else {
 | 
			
		||||
@ -567,6 +575,10 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
 | 
			
		||||
	singleton.Conf.Site.CustomCode = sf.CustomCode
 | 
			
		||||
	singleton.Conf.Site.ViewPassword = sf.ViewPassword
 | 
			
		||||
	singleton.Conf.Oauth2.Admin = sf.Admin
 | 
			
		||||
	// 保证NotificationTag不为空
 | 
			
		||||
	if singleton.Conf.IPChangeNotificationTag == "" {
 | 
			
		||||
		singleton.Conf.IPChangeNotificationTag = "default"
 | 
			
		||||
	}
 | 
			
		||||
	if err := singleton.Conf.Save(); err != nil {
 | 
			
		||||
		c.JSON(http.StatusOK, model.Response{
 | 
			
		||||
			Code:    http.StatusBadRequest,
 | 
			
		||||
 | 
			
		||||
@ -53,7 +53,7 @@
 | 
			
		||||
                        value="{{.Conf.IgnoredIPNotification}}">
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="field">
 | 
			
		||||
                    <label>提醒发送指定的通知分组</label>
 | 
			
		||||
                    <label>提醒发送至指定的通知分组</label>
 | 
			
		||||
                    <input type="text" name="IPChangeNotificationTag" placeholder="" value="{{.Conf.IPChangeNotificationTag}}">
 | 
			
		||||
                </div>
 | 
			
		||||
                <div class="field">
 | 
			
		||||
 | 
			
		||||
@ -149,23 +149,23 @@ func (ss *ServiceSentinel) loadMonitorHistory() {
 | 
			
		||||
	var err error
 | 
			
		||||
	ss.monitorsLock.Lock()
 | 
			
		||||
	defer ss.monitorsLock.Unlock()
 | 
			
		||||
	for _, monitor := range monitors {
 | 
			
		||||
	for i := range monitors {
 | 
			
		||||
		// 旧版本可能不存在通知组 为其设置默认组
 | 
			
		||||
		if monitor.NotificationTag == "" {
 | 
			
		||||
			monitor.NotificationTag = "default"
 | 
			
		||||
			DB.Save(monitor)
 | 
			
		||||
		if monitors[i].NotificationTag == "" {
 | 
			
		||||
			monitors[i].NotificationTag = "default"
 | 
			
		||||
			DB.Save(monitors[i])
 | 
			
		||||
		}
 | 
			
		||||
		task := *monitor
 | 
			
		||||
		task := *monitors[i]
 | 
			
		||||
		// 通过cron定时将服务监控任务传递给任务调度管道
 | 
			
		||||
		monitor.CronJobID, err = Cron.AddFunc(task.CronSpec(), func() {
 | 
			
		||||
		monitors[i].CronJobID, err = Cron.AddFunc(task.CronSpec(), func() {
 | 
			
		||||
			ss.dispatchBus <- task
 | 
			
		||||
		})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		ss.monitors[monitor.ID] = monitor
 | 
			
		||||
		ss.serviceCurrentStatusData[monitor.ID] = make([]model.MonitorHistory, _CurrentStatusSize)
 | 
			
		||||
		ss.serviceStatusToday[monitor.ID] = &_TodayStatsOfMonitor{}
 | 
			
		||||
		ss.monitors[monitors[i].ID] = monitors[i]
 | 
			
		||||
		ss.serviceCurrentStatusData[monitors[i].ID] = make([]model.MonitorHistory, _CurrentStatusSize)
 | 
			
		||||
		ss.serviceStatusToday[monitors[i].ID] = &_TodayStatsOfMonitor{}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	year, month, day := time.Now().Date()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user