0f5a2f4ef5
* enable more linters * Run gofmt -s * run goimports * run unconvert * fix naked return * fix misspellings * fix ineffectual assigments * fix missing declaration * don't use deprecated grpc.Errof * check errors in tests * run gofmt -w -r "assert.Nil(err) -> assert.NoError(err)" * fix directory permissions * don't use nil Context * simplify boolean expressions * use bytes.Equal instead of bytes.Compare * merge variable declarations, remove redundant returns * fix some golint errors * run goimports * handle more errors * delete empty TestMain * delete empty TestMain * ignore examples for now * fix lint errors * remove unused values * more fixes * run gofmt -w -s . * add more comments * fix naming * more lint fixes * try switching travis to go1.11 * fix unnecessary conversions * fix deprecated methods * use go1.10 and disable gofmt/goimports for now * switch to 1.10 * don't re-enable gofmt and goimports * switch covermode to atomic because of -race * gofmt
44 lines
1.2 KiB
Go
44 lines
1.2 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"`
|
|
MinInlineSegmentSize int64 `default:"1240" help:"minimum inline segment size"`
|
|
MaxInlineSegmentSize int `default:"8000" help:"maximum inline segment size"`
|
|
}
|
|
|
|
// 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(), c))
|
|
|
|
return server.Run(ctx)
|
|
}
|