backend: Unify backend construction using factory and registry

This unified construction removes most backend-specific code from
global.go. The backend registry will also enable integration tests to
use custom backends if necessary.
This commit is contained in:
Michael Eischer 2023-06-08 13:04:34 +02:00
parent 56836364a4
commit 7d12c29286
16 changed files with 235 additions and 142 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/backend/layout"
"github.com/restic/restic/internal/backend/location"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic"
@ -34,6 +35,10 @@ type beSwift struct {
// ensure statically that *beSwift implements restic.Backend.
var _ restic.Backend = &beSwift{}
func NewFactory() location.Factory {
return location.NewHTTPBackendFactory(ParseConfig, location.NoPassword, Open, Open)
}
// Open opens the swift backend at a container in region. The container is
// created if it does not exist yet.
func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (restic.Backend, error) {