storj/cmd/overlay/cache.go
Egon Elbre 0f5a2f4ef5 Enable more linters (#272)
* 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
2018-08-27 11:28:16 -06:00

50 lines
1.2 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"net/url"
"strconv"
"go.uber.org/zap"
"storj.io/storj/pkg/overlay"
)
type cacheConfig struct {
NodesPath string `help:"the path to a JSON file containing an object with IP keys and nodeID values"`
DatabaseURL string `help:"the database connection string to use"`
}
func (c cacheConfig) open() (*overlay.Cache, error) {
dburl, err := url.Parse(c.DatabaseURL)
if err != nil {
return nil, Error.Wrap(err)
}
var cache *overlay.Cache
switch dburl.Scheme {
case "bolt":
cache, err = overlay.NewBoltOverlayCache(dburl.Path, nil)
if err != nil {
return nil, err
}
zap.S().Info("Starting overlay cache with BoltDB")
case "redis":
db, err := strconv.Atoi(dburl.Query().Get("db"))
if err != nil {
return nil, Error.New("invalid db: %s", err)
}
cache, err = overlay.NewRedisOverlayCache(dburl.Host, overlay.GetUserPassword(dburl), db, nil)
if err != nil {
return nil, err
}
zap.S().Info("Starting overlay cache with Redis")
default:
return nil, Error.New("database scheme not supported: %s", dburl.Scheme)
}
return cache, nil
}