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

46 lines
923 B
Go
Raw Normal View History

package backblaze
import (
"context"
"fmt"
"github.com/kurin/blazer/b2"
"github.com/sirupsen/logrus"
)
type BackBlaze struct {
2023-10-01 14:35:50 +02:00
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{
2023-10-01 14:35:50 +02:00
logger: logger,
b2Client: b2Client,
bbID: bbID,
bbKey: bbKey,
}, nil
}
2023-10-01 14:35:50 +02:00
type BackBlazeOptions struct {
Bucket string
Dir string
FilePath string
MaxWorkers int
ConcurrentUploads int
}
2023-10-01 14:35:50 +02:00
func (b *BackBlaze) WithOptions(options BackBlazeOptions) *BackBlaze {
b.options = options
return b
}