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

51 lines
1.0 KiB
Go
Raw Normal View History

package backblaze
import (
"context"
"fmt"
"runtime"
"github.com/kurin/blazer/b2"
"github.com/sirupsen/logrus"
)
type BackBlaze struct {
logger *logrus.Logger
bucketName string
bbID string
bbKey string
dir string
filePath string
maxWorkers int
b2Client *b2.Client
}
// 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,
maxWorkers: runtime.NumCPU(),
}, nil
}
func (b *BackBlaze) WithBucket(bucketName string) *BackBlaze {
b.bucketName = bucketName
return b
}
func (b *BackBlaze) WithDir(dir string) *BackBlaze {
b.dir = dir
return b
}
func (b *BackBlaze) WithFile(filePath string) *BackBlaze {
b.filePath = filePath
return b
}