f80185a807
* Don't use url.Parse for bolt paths: filepaths may not be valid URL-s. * go.mod: update dependencies * README.md: add Windows instructions * pkg/overlay: check for the correct path and text in error * pkg/overlay: fix tests for windows * pkg/piecestore: make windows tests pass * pkg/telemetry: skip test, as it doesn't shutdown nicely * storage/redis: ensure that redis is clean before running tests
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package pointerdb
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/storj/pkg/provider"
|
|
"storj.io/storj/pkg/utils"
|
|
proto "storj.io/storj/protos/pointerdb"
|
|
"storj.io/storj/storage/boltdb"
|
|
)
|
|
|
|
// Config is a configuration struct that is everything you need to start a
|
|
// PointerDB responsibility
|
|
type Config struct {
|
|
DatabaseURL string `help:"the database connection string to use" default:"bolt://$CONFDIR/pointerdb.db"`
|
|
}
|
|
|
|
// Run implements the provider.Responsibility interface
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) error {
|
|
dburl, err := utils.ParseURL(c.DatabaseURL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if dburl.Scheme != "bolt" {
|
|
return Error.New("unsupported db scheme: %s", dburl.Scheme)
|
|
}
|
|
bdb, err := boltdb.NewClient(zap.L(), dburl.Path, boltdb.PointerBucket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() { _ = bdb.Close() }()
|
|
|
|
proto.RegisterPointerDBServer(server.GRPC(), NewServer(bdb, zap.L()))
|
|
|
|
return server.Run(ctx)
|
|
}
|