mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-21 21:10:26 +01:00
Use go 1.20, join errors using stdlib (#182)
* Use go 1.20, join errors using stdlib * Use go 1.20 proper
This commit is contained in:
parent
1e36bd3eb7
commit
2d37e08743
@ -1,7 +1,7 @@
|
||||
# Copyright 2021 - Offen Authors <hioffen@posteo.de>
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
FROM golang:1.19-alpine as builder
|
||||
FROM golang:1.20-alpine as builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
@ -4,10 +4,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
)
|
||||
|
||||
// hook contains a queued action that can be trigger them when the script
|
||||
@ -52,7 +51,7 @@ func (s *script) runHooks(err error) error {
|
||||
}
|
||||
}
|
||||
if len(actionErrors) != 0 {
|
||||
return utilities.Join(actionErrors...)
|
||||
return errors.Join(actionErrors...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
sTypes "github.com/containrrr/shoutrrr/pkg/types"
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
)
|
||||
|
||||
//go:embed notifications.tmpl
|
||||
@ -69,7 +69,7 @@ func (s *script) sendNotification(title, body string) error {
|
||||
}
|
||||
}
|
||||
if len(errs) != 0 {
|
||||
return fmt.Errorf("sendNotification: error sending message: %w", utilities.Join(errs...))
|
||||
return fmt.Errorf("sendNotification: error sending message: %w", errors.Join(errs...))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
@ -20,7 +21,6 @@ import (
|
||||
"github.com/offen/docker-volume-backup/internal/storage/s3"
|
||||
"github.com/offen/docker-volume-backup/internal/storage/ssh"
|
||||
"github.com/offen/docker-volume-backup/internal/storage/webdav"
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
|
||||
"github.com/containrrr/shoutrrr"
|
||||
"github.com/containrrr/shoutrrr/pkg/router"
|
||||
@ -329,7 +329,7 @@ func (s *script) stopContainers() (func() error, error) {
|
||||
stopError = fmt.Errorf(
|
||||
"stopContainers: %d error(s) stopping containers: %w",
|
||||
len(stopErrors),
|
||||
utilities.Join(stopErrors...),
|
||||
errors.Join(stopErrors...),
|
||||
)
|
||||
}
|
||||
|
||||
@ -380,7 +380,7 @@ func (s *script) stopContainers() (func() error, error) {
|
||||
return fmt.Errorf(
|
||||
"stopContainers: %d error(s) restarting containers and services: %w",
|
||||
len(restartErrors),
|
||||
utilities.Join(restartErrors...),
|
||||
errors.Join(restartErrors...),
|
||||
)
|
||||
}
|
||||
s.logger.Infof(
|
||||
|
@ -6,6 +6,7 @@ package azure
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -18,7 +19,6 @@ import (
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
|
||||
"github.com/offen/docker-volume-backup/internal/storage"
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
)
|
||||
|
||||
type azureBlobStorage struct {
|
||||
@ -135,21 +135,21 @@ func (b *azureBlobStorage) Prune(deadline time.Time, pruningPrefix string) (*sto
|
||||
if err := b.DoPrune(b.Name(), len(matches), int(totalCount), "Azure Blob Storage backup(s)", func() error {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(matches))
|
||||
var errors []error
|
||||
var errs []error
|
||||
|
||||
for _, match := range matches {
|
||||
name := match
|
||||
go func() {
|
||||
_, err := b.client.DeleteBlob(context.Background(), b.containerName, name, nil)
|
||||
if err != nil {
|
||||
errors = append(errors, err)
|
||||
errs = append(errs, err)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
if len(errors) != 0 {
|
||||
return utilities.Join(errors...)
|
||||
if len(errs) != 0 {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
@ -4,6 +4,7 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/offen/docker-volume-backup/internal/storage"
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
)
|
||||
|
||||
type localStorage struct {
|
||||
@ -127,7 +127,7 @@ func (b *localStorage) Prune(deadline time.Time, pruningPrefix string) (*storage
|
||||
return fmt.Errorf(
|
||||
"(*localStorage).Prune: %d error(s) deleting local files, starting with: %w",
|
||||
len(removeErrors),
|
||||
utilities.Join(removeErrors...),
|
||||
errors.Join(removeErrors...),
|
||||
)
|
||||
}
|
||||
return nil
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/offen/docker-volume-backup/internal/storage"
|
||||
"github.com/offen/docker-volume-backup/internal/utilities"
|
||||
)
|
||||
|
||||
type s3Storage struct {
|
||||
@ -159,7 +158,7 @@ func (b *s3Storage) Prune(deadline time.Time, pruningPrefix string) (*storage.Pr
|
||||
}
|
||||
}
|
||||
if len(removeErrors) != 0 {
|
||||
return utilities.Join(removeErrors...)
|
||||
return errors.Join(removeErrors...)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright 2022 - Offen Authors <hioffen@posteo.de>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package utilities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Join takes a list of errors and joins them into a single error
|
||||
func Join(errs ...error) error {
|
||||
if len(errs) == 1 {
|
||||
return errs[0]
|
||||
}
|
||||
var msgs []string
|
||||
for _, err := range errs {
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
msgs = append(msgs, err.Error())
|
||||
}
|
||||
return errors.New("[" + strings.Join(msgs, ", ") + "]")
|
||||
}
|
Loading…
Reference in New Issue
Block a user