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