Merge pull request #4157 from ywk253100/180129_gas

Fix code issues found by Gas
This commit is contained in:
Wenkai Yin 2018-01-29 16:00:00 +08:00 committed by GitHub
commit fbef56e071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 7 deletions

View File

@ -100,7 +100,9 @@ func schedulePolicy(notification ScanPolicyNotification) error {
OffsetTime: notification.DailyTime,
})
attachTask := task.NewScanAllTask()
schedulePolicy.AttachTasks(attachTask)
if err := schedulePolicy.AttachTasks(attachTask); err != nil {
return err
}
return scheduler.DefaultScheduler.Schedule(schedulePolicy)
}

View File

@ -100,7 +100,9 @@ func TestTCPConn(addr string, timeout, interval int) error {
time.Sleep(time.Duration(interval) * time.Second)
continue
}
conn.Close()
if err = conn.Close(); err != nil {
log.Errorf("failed to close the connection: %v", err)
}
success <- 1
break
}

View File

@ -28,7 +28,7 @@ func NewLogger(j Job) (*log.Logger, error) {
logFile := j.LogPath()
d := filepath.Dir(logFile)
if _, err := os.Stat(d); os.IsNotExist(err) {
err := os.MkdirAll(d, 0755)
err := os.MkdirAll(d, 0700)
if err != nil {
log.Errorf("Failed to create directory for log file %s, the error: %v", logFile, err)
}

View File

@ -158,9 +158,11 @@ func (l *Auth) PostAuthenticate(u *models.User) error {
if !Re.MatchString(u.Email) {
log.Debugf("Not a valid email address: %v, skip to sync", u.Email)
} else {
dao.ChangeUserProfile(*u, "Email")
if err = dao.ChangeUserProfile(*u, "Email"); err != nil {
u.Email = dbUser.Email
log.Errorf("failed to sync user email: %v", err)
}
}
u.Email = dbUser.Email
}
return nil

View File

@ -116,7 +116,9 @@ func main() {
scheduler.DefaultScheduler.Start()
//Subscribe the policy change topic.
notifier.Subscribe(notifier.ScanAllPolicyTopic, &notifier.ScanPolicyNotificationHandler{})
if err = notifier.Subscribe(notifier.ScanAllPolicyTopic, &notifier.ScanPolicyNotificationHandler{}); err != nil {
log.Errorf("failed to subscribe scan all policy change topic: %v", err)
}
//Get policy configuration.
scanAllPolicy := config.ScanAllPolicy()
@ -129,7 +131,10 @@ func main() {
}
//Send notification to handle first policy change.
notifier.Publish(notifier.ScanAllPolicyTopic, notifier.ScanPolicyNotification{Type: scanAllPolicy.Type, DailyTime: (int64)(dailyTime)})
if err = notifier.Publish(notifier.ScanAllPolicyTopic,
notifier.ScanPolicyNotification{Type: scanAllPolicy.Type, DailyTime: (int64)(dailyTime)}); err != nil {
log.Errorf("failed to publish scan all policy topic: %v", err)
}
}
if err := core.Init(); err != nil {