backblaze-backup/internal/services/backblaze/backblaze.go

46 lines
923 B
Go

package backblaze
import (
"context"
"fmt"
"github.com/kurin/blazer/b2"
"github.com/sirupsen/logrus"
)
type BackBlaze struct {
logger *logrus.Logger
b2Client *b2.Client
bbID string
bbKey string
options BackBlazeOptions
}
// NewBackBlaze initializes a new BackBlaze struct with given BackBlaze ID and Key.
func NewBackBlaze(ctx context.Context, logger *logrus.Logger, bbID, bbKey string) (*BackBlaze, error) {
b2Client, err := b2.NewClient(ctx, bbID, bbKey)
if err != nil {
return nil, fmt.Errorf("b2.NewClient %w", err)
}
return &BackBlaze{
logger: logger,
b2Client: b2Client,
bbID: bbID,
bbKey: bbKey,
}, nil
}
type BackBlazeOptions struct {
Bucket string
Dir string
FilePath string
MaxWorkers int
ConcurrentUploads int
}
func (b *BackBlaze) WithOptions(options BackBlazeOptions) *BackBlaze {
b.options = options
return b
}