location: make genericBackendFactory private

This commit is contained in:
Michael Eischer 2023-06-08 15:18:43 +02:00
parent 3325a7c862
commit 19ac12d95b

View file

@ -36,35 +36,35 @@ type Factory interface {
Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error) Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error)
} }
type GenericBackendFactory[C any, T restic.Backend] struct { type genericBackendFactory[C any, T restic.Backend] struct {
parseConfigFn func(s string) (*C, error) parseConfigFn func(s string) (*C, error)
stripPasswordFn func(s string) string stripPasswordFn func(s string) string
createFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter) (T, error) createFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter) (T, error)
openFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter) (T, error) openFn func(ctx context.Context, cfg C, rt http.RoundTripper, lim limiter.Limiter) (T, error)
} }
func (f *GenericBackendFactory[C, T]) ParseConfig(s string) (interface{}, error) { func (f *genericBackendFactory[C, T]) ParseConfig(s string) (interface{}, error) {
return f.parseConfigFn(s) return f.parseConfigFn(s)
} }
func (f *GenericBackendFactory[C, T]) StripPassword(s string) string { func (f *genericBackendFactory[C, T]) StripPassword(s string) string {
if f.stripPasswordFn != nil { if f.stripPasswordFn != nil {
return f.stripPasswordFn(s) return f.stripPasswordFn(s)
} }
return s return s
} }
func (f *GenericBackendFactory[C, T]) Create(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error) { func (f *genericBackendFactory[C, T]) Create(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error) {
return f.createFn(ctx, *cfg.(*C), rt, lim) return f.createFn(ctx, *cfg.(*C), rt, lim)
} }
func (f *GenericBackendFactory[C, T]) Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error) { func (f *genericBackendFactory[C, T]) Open(ctx context.Context, cfg interface{}, rt http.RoundTripper, lim limiter.Limiter) (restic.Backend, error) {
return f.openFn(ctx, *cfg.(*C), rt, lim) return f.openFn(ctx, *cfg.(*C), rt, lim)
} }
func NewHTTPBackendFactory[C any, T restic.Backend](parseConfigFn func(s string) (*C, error), func NewHTTPBackendFactory[C any, T restic.Backend](parseConfigFn func(s string) (*C, error),
stripPasswordFn func(s string) string, stripPasswordFn func(s string) string,
createFn func(ctx context.Context, cfg C, rt http.RoundTripper) (T, error), createFn func(ctx context.Context, cfg C, rt http.RoundTripper) (T, error),
openFn func(ctx context.Context, cfg C, rt http.RoundTripper) (T, error)) *GenericBackendFactory[C, T] { openFn func(ctx context.Context, cfg C, rt http.RoundTripper) (T, error)) Factory {
return &GenericBackendFactory[C, T]{ return &genericBackendFactory[C, T]{
parseConfigFn: parseConfigFn, parseConfigFn: parseConfigFn,
stripPasswordFn: stripPasswordFn, stripPasswordFn: stripPasswordFn,
createFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter) (T, error) { createFn: func(ctx context.Context, cfg C, rt http.RoundTripper, _ limiter.Limiter) (T, error) {
@ -79,9 +79,9 @@ func NewHTTPBackendFactory[C any, T restic.Backend](parseConfigFn func(s string)
func NewLimitedBackendFactory[C any, T restic.Backend](parseConfigFn func(s string) (*C, error), func NewLimitedBackendFactory[C any, T restic.Backend](parseConfigFn func(s string) (*C, error),
stripPasswordFn func(s string) string, stripPasswordFn func(s string) string,
createFn func(ctx context.Context, cfg C, lim limiter.Limiter) (T, error), createFn func(ctx context.Context, cfg C, lim limiter.Limiter) (T, error),
openFn func(ctx context.Context, cfg C, lim limiter.Limiter) (T, error)) *GenericBackendFactory[C, T] { openFn func(ctx context.Context, cfg C, lim limiter.Limiter) (T, error)) Factory {
return &GenericBackendFactory[C, T]{ return &genericBackendFactory[C, T]{
parseConfigFn: parseConfigFn, parseConfigFn: parseConfigFn,
stripPasswordFn: stripPasswordFn, stripPasswordFn: stripPasswordFn,
createFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter) (T, error) { createFn: func(ctx context.Context, cfg C, _ http.RoundTripper, lim limiter.Limiter) (T, error) {