Merge branch 'master' into 1515-metalinter-nakedret

This commit is contained in:
Cody Soyland 2018-07-19 07:52:58 -05:00
commit 3ca51989c2
24 changed files with 53 additions and 92 deletions

View file

@ -113,10 +113,12 @@ gometalinter: require-gometalinter
gometalinter --vendor --disable-all \
--deadline=60s \
--enable=deadcode \
--enable=gochecknoinits \
--enable=gofmt \
--enable=goimports \
--enable=gotype \
--enable=gotypex \
--enable=ineffassign \
--enable=interfacer \
--enable=misspell \
--enable=nakedret \

View file

@ -37,12 +37,8 @@ type broadcaster interface {
// TODO add at least a single "isMessage()" method.
type Message interface{}
func init() {
NopBroadcaster = &nopBroadcaster{}
}
// NopBroadcaster represents a Broadcaster that doesn't do anything.
var NopBroadcaster broadcaster
var NopBroadcaster broadcaster = &nopBroadcaster{}
type nopBroadcaster struct{}

View file

@ -27,7 +27,7 @@ import (
var checker *ctl.CheckCommand
func newCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
func newCheckCommand(_ io.Reader, _, _ io.Writer) *cobra.Command {
checker = ctl.NewCheckCommand(os.Stdin, os.Stdout, os.Stderr)
checkCmd := &cobra.Command{
Use: "check <path> [path2]...",
@ -48,7 +48,3 @@ Performs a consistency check on data files.
}
return checkCmd
}
func init() {
subcommandFns["check"] = newCheckCommand
}

View file

@ -49,7 +49,3 @@ func newConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command
return confCmd
}
func init() {
subcommandFns["config"] = newConfigCommand
}

View file

@ -26,7 +26,7 @@ import (
var Exporter *ctl.ExportCommand
func newExportCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
func newExportCommand(_ io.Reader, _, _ io.Writer) *cobra.Command {
Exporter = ctl.NewExportCommand(os.Stdin, os.Stdout, os.Stderr)
exportCmd := &cobra.Command{
Use: "export",
@ -58,7 +58,3 @@ The file does not contain any headers.
return exportCmd
}
func init() {
subcommandFns["export"] = newExportCommand
}

View file

@ -26,7 +26,7 @@ import (
var generateConf *ctl.GenerateConfigCommand
func newGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
func newGenerateConfigCommand(_ io.Reader, _, _ io.Writer) *cobra.Command {
generateConf = ctl.NewGenerateConfigCommand(os.Stdin, os.Stdout, os.Stderr)
confCmd := &cobra.Command{
Use: "generate-config",
@ -43,7 +43,3 @@ func newGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.
return confCmd
}
func init() {
subcommandFns["generate-config"] = newGenerateConfigCommand
}

View file

@ -65,7 +65,3 @@ omitted. If it is present then its format should be YYYY-MM-DDTHH:MM.
return importCmd
}
func init() {
subcommandFns["import"] = newImportCommand
}

View file

@ -27,7 +27,7 @@ import (
var inspector *ctl.InspectCommand
func newInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
func newInspectCommand(_ io.Reader, _, _ io.Writer) *cobra.Command {
inspector = ctl.NewInspectCommand(os.Stdin, os.Stdout, os.Stderr)
inspectCmd := &cobra.Command{
@ -51,7 +51,3 @@ Inspects a data file and provides stats.
}
return inspectCmd
}
func init() {
subcommandFns["inspect"] = newInspectCommand
}

View file

@ -25,10 +25,6 @@ import (
"github.com/spf13/viper"
)
// TODO maybe give this an Add method which will ensure two command
// with same name aren't added
var subcommandFns = map[string]func(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command{}
func NewRootCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
productName := "Pilosa " + pilosa.Version
if pilosa.EnterpriseEnabled {
@ -69,9 +65,15 @@ Build Time: ` + pilosa.BuildTime + "\n",
rc.PersistentFlags().Bool("dry-run", false, "stop before executing")
_ = rc.PersistentFlags().MarkHidden("dry-run")
rc.PersistentFlags().StringP("config", "c", "", "Configuration file to read from.")
for _, subcomFn := range subcommandFns {
rc.AddCommand(subcomFn(stdin, stdout, stderr))
}
rc.AddCommand(newCheckCommand(stdin, stdout, stderr))
rc.AddCommand(newConfigCommand(stdin, stdout, stderr))
rc.AddCommand(newExportCommand(stdin, stdout, stderr))
rc.AddCommand(newGenerateConfigCommand(stdin, stdout, stderr))
rc.AddCommand(newImportCommand(stdin, stdout, stderr))
rc.AddCommand(newInspectCommand(stdin, stdout, stderr))
rc.AddCommand(newServeCmd(stdin, stdout, stderr))
rc.SetOutput(stderr)
return rc
}

View file

@ -50,7 +50,3 @@ on the configured port.`,
ctl.BuildServerFlags(serveCmd, Server)
return serveCmd
}
func init() {
subcommandFns["server"] = newServeCmd
}

View file

@ -203,6 +203,9 @@ func TestImportCommand_BugOverwriteValue(t *testing.T) {
file.Close()
file, err = ioutil.TempFile("", "import-value2.csv")
if err != nil {
t.Fatalf("Error creating tempfile: %s", err)
}
file.Write([]byte("0,16\n"))
cm.Paths = []string{file.Name()}
err = cm.Run(ctx)
@ -212,6 +215,9 @@ func TestImportCommand_BugOverwriteValue(t *testing.T) {
file.Close()
file, err = ioutil.TempFile("", "import-value3.csv")
if err != nil {
t.Fatalf("Error creating tempfile: %s", err)
}
file.Write([]byte("0,19\n"))
cm.Paths = []string{file.Name()}
err = cm.Run(ctx)

View file

@ -31,6 +31,9 @@ func TestInspectCommand_Run(t *testing.T) {
cm := NewInspectCommand(stdin, w, w)
file, err := ioutil.TempFile("", "inspectTest")
if err != nil {
t.Fatalf("Error creating tempfile: %s", err)
}
file.Write([]byte("12358267538963"))
file.Close()
cm.Path = file.Name()

View file

@ -32,7 +32,6 @@
package b
import (
"fmt"
"io"
"sync"
@ -40,20 +39,12 @@ import (
)
const (
// kx must be >= 2
kx = 128 //TODO benchmark tune this number if using custom key/value type(s).
// kd must be >= 1
kd = 128 //TODO benchmark tune this number if using custom key/value type(s).
)
func init() {
if kd < 1 {
panic(fmt.Errorf("kd %d: out of range", kd))
}
if kx < 2 {
panic(fmt.Errorf("kx %d: out of range", kx))
}
}
var (
btDPool = sync.Pool{New: func() interface{} { return &d{} }}
btEPool = btEpool{sync.Pool{New: func() interface{} { return &enumerator{} }}}

View file

@ -26,7 +26,7 @@ import (
"github.com/pilosa/pilosa/roaring"
)
func init() {
func init() { // nolint: gochecknoinits
// Replace Bitmap constructor with B+Tree implementation
roaring.NewFileBitmap = b.NewBTreeBitmap
}

View file

@ -584,9 +584,9 @@ func (f *fragment) sum(filter *Row, bitDepth uint) (sum, count uint64, err error
//
// 10*(2^0) + 4*(2^1) + 3*(2^2) = 30
//
var cnt uint64
for i := uint(0); i < bitDepth; i++ {
row := f.row(uint64(i))
cnt := uint64(0)
if filter != nil {
cnt = row.intersectionCount(filter)
} else {
@ -1714,10 +1714,11 @@ func (f *fragment) rows() []uint64 {
}
func (f *fragment) rowsForColumn(columnID uint64) []uint64 {
var colKey uint64
colID := columnID % ShardWidth
i, _ := f.storage.Containers.Iterator(0)
colKey := uint64(0)
colVal := uint16(colID & 0xFFFF)
rows := make([]uint64, 0)

6
gc.go
View file

@ -23,12 +23,8 @@ type GCNotifier interface {
AfterGC() <-chan struct{}
}
func init() {
NopGCNotifier = &nopGCNotifier{}
}
// NopGCNotifier represents a GCNotifier that doesn't do anything.
var NopGCNotifier GCNotifier
var NopGCNotifier GCNotifier = &nopGCNotifier{}
type nopGCNotifier struct{}

View file

@ -29,13 +29,6 @@ import (
"github.com/pilosa/pilosa/test"
)
var defaultClient *gohttp.Client
func init() {
defaultClient = http.GetHTTPClient(nil)
}
// Test distributed TopN Row count across 3 nodes.
func TestClient_MultiNode(t *testing.T) {
c := test.MustRunCluster(t, 3,
@ -125,9 +118,9 @@ func TestClient_MultiNode(t *testing.T) {
// Connect to each node to compare results.
client := make([]*Client, 3)
client[0] = MustNewClient(c[0].URL(), defaultClient)
client[1] = MustNewClient(c[1].URL(), defaultClient)
client[2] = MustNewClient(c[2].URL(), defaultClient)
client[0] = MustNewClient(c[0].URL(), http.GetHTTPClient(nil))
client[1] = MustNewClient(c[1].URL(), http.GetHTTPClient(nil))
client[2] = MustNewClient(c[2].URL(), http.GetHTTPClient(nil))
topN := 4
queryRequest := &pilosa.QueryRequest{
@ -191,7 +184,7 @@ func TestClient_Import(t *testing.T) {
hldr.Row("i", "f", 0)
// Send import request.
c := MustNewClient(host, defaultClient)
c := MustNewClient(host, http.GetHTTPClient(nil))
if err := c.Import(context.Background(), "i", "f", 0, []pilosa.Bit{
{RowID: 0, ColumnID: 1},
{RowID: 0, ColumnID: 5},
@ -226,7 +219,7 @@ func TestClient_ImportValue(t *testing.T) {
}
// Send import request.
c := MustNewClient(host, defaultClient)
c := MustNewClient(host, http.GetHTTPClient(nil))
if err := c.ImportValue(context.Background(), "i", "f", 0, []pilosa.FieldValue{
{ColumnID: 1, Value: -10},
{ColumnID: 2, Value: 20},
@ -287,7 +280,7 @@ func TestClient_FragmentBlocks(t *testing.T) {
// Set a bit on a different shard.
hldr.SetBit("i", "f", 0, 1)
c := MustNewClient(cmd.URL(), defaultClient)
c := MustNewClient(cmd.URL(), http.GetHTTPClient(nil))
blocks, err := c.FragmentBlocks(context.Background(), nil, "i", "f", 0)
if err != nil {
t.Fatal(err)

View file

@ -28,12 +28,8 @@ type Logger interface {
Debugf(format string, v ...interface{})
}
func init() {
NopLogger = &nopLogger{}
}
// NopLogger represents a Logger that doesn't do anything.
var NopLogger Logger
var NopLogger Logger = &nopLogger{}
type nopLogger struct{}

View file

@ -2276,7 +2276,7 @@ func TestIteratorRuns(t *testing.T) {
t.Fatalf("iterator did not seek correctly in multiple containers: %v\n", itr)
}
val, eof = itr.Next()
itr.Next()
val, eof = itr.Next()
if !(val == 0 && eof) {
t.Fatalf("iterator did not eof correctly: %d, %v\n", val, eof)

View file

@ -44,10 +44,6 @@ import (
"github.com/pkg/errors"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
type loggerLogger interface {
pilosa.Logger
Logger() *log.Logger
@ -126,6 +122,9 @@ func NewCommand(stdin io.Reader, stdout, stderr io.Writer, opts ...CommandOption
func (m *Command) Start() (err error) {
defer close(m.Started)
// Seed random number generator
rand.Seed(time.Now().UTC().UnixNano())
// SetupServer
err = m.SetupServer()
if err != nil {

View file

@ -22,10 +22,6 @@ import (
"time"
)
func init() {
NopStatsClient = &nopStatsClient{}
}
// Expvar global expvar map.
var Expvar = expvar.NewMap("index")
@ -66,7 +62,7 @@ type StatsClient interface {
}
// NopStatsClient represents a client that doesn't do anything.
var NopStatsClient StatsClient
var NopStatsClient StatsClient = &nopStatsClient{}
type nopStatsClient struct{}

View file

@ -243,6 +243,9 @@ func MustDo(method, urlStr string, body string) *httpResponse {
urlStr,
strings.NewReader(body),
)
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")

View file

@ -40,6 +40,9 @@ func TestNewCluster(t *testing.T) {
cluster[0].URL()+"/status",
strings.NewReader(""),
)
if err != nil {
t.Fatalf("creating http request: %v", err)
}
req.Header.Set("Accept", "application/json")

View file

@ -19,7 +19,9 @@ var EnterpriseEnabled = false
var Version = "v0.0.0"
var BuildTime = "not recorded"
func init() {
// init sets the EnterpriseEnabled bool, based on the Enterprise string.
// This is needed because bools cannot be set with ldflags.
func init() { // nolint: gochecknoinits
if Enterprise == "1" {
EnterpriseEnabled = true
}