From ed63ededf1b12660f0e61b5526b27413d146e9cb Mon Sep 17 00:00:00 2001 From: Urko Date: Mon, 28 Aug 2023 11:18:50 +0200 Subject: [PATCH] fix: count --- License | 2 +- cmd/check.go | 22 +++++++++++----------- internal/services/email/email.go | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/License b/License index 7f4fd9a..f228b5f 100644 --- a/License +++ b/License @@ -1,6 +1,6 @@ ---- Definitions ---- license means right to use -author means who had initial idea, who research about jurisprudence and the who who started, in this case : Urko: Bein. +author means who had initial idea, who research about jurisprudence and who started, in this case : Urko: Bein. contributors means every man who has helped to improve this software diff --git a/cmd/check.go b/cmd/check.go index ba5d89e..0d2dc49 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -76,17 +76,17 @@ var Check = &cobra.Command{ go b.CompareConcurrent(ctx, backupDir, bucketName, msgChan) reportBuilder := strings.Builder{} - countLocalFiles := 0 + countLocal := 0 countOK := 0 reportBuilder.WriteString(fmt.Sprintf("Local files within `%s` path already in `%s` bucket:\n", backupDir, bucketName)) cloudBuilder := strings.Builder{} cloudBuilder.WriteString(fmt.Sprintf("List of B2 files within `%s` bucket not found in local path `%s`\n", bucketName, backupDir)) - countNotInLocalBuffer := 0 + countNotInLocal := 0 localBuilder := strings.Builder{} localBuilder.WriteString(fmt.Sprintf("List of local files in `%s` not found in B2 bucket `%s`\n", backupDir, bucketName)) - countNotInCloudBuffer := 0 + countNotInCloud := 0 loop: for { @@ -102,19 +102,19 @@ var Check = &cobra.Command{ break loop case msg := <-msgChan: if msg.Err == nil && msg.File == "" { - countLocalFiles = msg.LocalCount + countLocal = msg.LocalCount break loop } if errors.Is(msg.Err, backblaze.ErrCloudNotInLocal) { logger.Debug(msg.File + ": B2 file not found in local") cloudBuilder.WriteString(msg.File + "\n") - countNotInLocalBuffer++ + countNotInLocal++ continue } if errors.Is(msg.Err, backblaze.ErrLocalNotInCloud) { logger.Debug(msg.File + ": local file not found in B2") localBuilder.WriteString(msg.File + "\n") - countNotInCloudBuffer++ + countNotInCloud++ continue } reportBuilder.WriteString(msg.File + " OK" + "\n") @@ -122,11 +122,11 @@ var Check = &cobra.Command{ } } - if countNotInCloudBuffer > 0 { + if countNotInCloud > 0 { reportBuilder.WriteString("\n") reportBuilder.WriteString(cloudBuilder.String()) } - if countNotInLocalBuffer > 0 { + if countNotInLocal > 0 { reportBuilder.WriteString("\n") reportBuilder.WriteString(localBuilder.String()) } @@ -135,10 +135,10 @@ var Check = &cobra.Command{ To: cfg.MailTo, Bucket: bucketName, BackupDir: backupDir, - CountLocal: countNotInLocalBuffer, - CountCloud: countNotInCloudBuffer, + CountNotInLocal: countNotInLocal, + CountNotInCloud: countNotInCloud, CountOK: countOK, - CountLocalFiles: countLocalFiles, + CountLocal: countLocal, Attachments: []email.EmailAttachment{{File: bytes.NewReader([]byte(reportBuilder.String())), Title: fmt.Sprintf("%s-check-report.txt", bucketName)}}, }); err != nil { panic(fmt.Errorf("error while send email: %w", err)) diff --git a/internal/services/email/email.go b/internal/services/email/email.go index 1d7e2b3..9d6aff3 100644 --- a/internal/services/email/email.go +++ b/internal/services/email/email.go @@ -32,10 +32,10 @@ type EmailWithAttachments struct { To string Bucket string BackupDir string - CountLocal int + CountNotInLocal int CountOK int - CountCloud int - CountLocalFiles int + CountNotInCloud int + CountLocal int Attachments []EmailAttachment } @@ -75,10 +75,10 @@ func NewMailService(config MailServiceConfig) *EmailService { func (e *EmailService) SendOK(emailData EmailWithAttachments) error { template := strings.Replace(htmlTemplate, "{{bucket}}", emailData.Bucket, -1) template = strings.Replace(template, "{{local_backup_path}}", emailData.BackupDir, -1) - template = strings.Replace(template, "{{count_ErrCloudNotInLocal}}", fmt.Sprint(emailData.CountCloud), -1) - template = strings.Replace(template, "{{count_ErrLocalNotInCloud}}", fmt.Sprint(emailData.CountLocal), -1) + template = strings.Replace(template, "{{count_ErrCloudNotInLocal}}", fmt.Sprint(emailData.CountNotInLocal), -1) + template = strings.Replace(template, "{{count_ErrLocalNotInCloud}}", fmt.Sprint(emailData.CountNotInCloud), -1) template = strings.Replace(template, "{{count_ok}}", fmt.Sprint(emailData.CountOK), -1) - template = strings.Replace(template, "{{count_local}}", fmt.Sprint(emailData.CountLocalFiles), -1) + template = strings.Replace(template, "{{count_local}}", fmt.Sprint(emailData.CountLocal), -1) msg, err := newMessage(e.from, emailData.To, subjectReport). withAttachments(template, emailData.Attachments)