From 377ae090d070738d7b8580ff5e08c1bea45c20b0 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Wed, 3 Sep 2014 18:17:26 -0400 Subject: [PATCH] additional golint issues resolved --- .../flexible_go/flexible_go.go | 2 +- .../flexible_go/flexible_go_test.go | 2 +- analysis/freq.go | 4 +-- analysis/token_map.go | 4 +-- analysis/type.go | 2 +- index/upside_down/upside_down.go | 24 +++++++------- index/upside_down/upside_down_test.go | 32 +++++++++---------- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/analysis/datetime_parsers/flexible_go/flexible_go.go b/analysis/datetime_parsers/flexible_go/flexible_go.go index 0ae61a1a..fa613d6e 100644 --- a/analysis/datetime_parsers/flexible_go/flexible_go.go +++ b/analysis/datetime_parsers/flexible_go/flexible_go.go @@ -36,7 +36,7 @@ func (p *FlexibleGoDateTimeParser) ParseDateTime(input string) (time.Time, error return rv, nil } } - return time.Time{}, analysis.InvalidDateTime + return time.Time{}, analysis.ErrInvalidDateTime } func FlexibleGoDateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) { diff --git a/analysis/datetime_parsers/flexible_go/flexible_go_test.go b/analysis/datetime_parsers/flexible_go/flexible_go_test.go index b5eedf46..37c14e95 100644 --- a/analysis/datetime_parsers/flexible_go/flexible_go_test.go +++ b/analysis/datetime_parsers/flexible_go/flexible_go_test.go @@ -53,7 +53,7 @@ func TestFlexibleDateTimeParser(t *testing.T) { { input: "not a date time", expectedTime: time.Time{}, - expectedError: analysis.InvalidDateTime, + expectedError: analysis.ErrInvalidDateTime, }, } diff --git a/analysis/freq.go b/analysis/freq.go index 4f34e9ec..b2e6c084 100644 --- a/analysis/freq.go +++ b/analysis/freq.go @@ -49,7 +49,7 @@ func (tfs TokenFrequencies) MergeAll(remoteField string, other TokenFrequencies) i := 0 for _, tf := range index { rv[i] = tf - i += 1 + i++ } return rv } @@ -83,7 +83,7 @@ func TokenFrequency(tokens TokenStream) TokenFrequencies { i := 0 for _, tf := range index { rv[i] = tf - i += 1 + i++ } return rv diff --git a/analysis/token_map.go b/analysis/token_map.go index a6bd5110..ade376c4 100644 --- a/analysis/token_map.go +++ b/analysis/token_map.go @@ -23,12 +23,12 @@ func NewTokenMap() TokenMap { return make(TokenMap, 0) } -func (s TokenMap) LoadFile(filename string) error { +func (t TokenMap) LoadFile(filename string) error { data, err := ioutil.ReadFile(filename) if err != nil { return err } - return s.LoadBytes(data) + return t.LoadBytes(data) } func (t TokenMap) LoadBytes(data []byte) error { diff --git a/analysis/type.go b/analysis/type.go index 143af86d..6ef61cb6 100644 --- a/analysis/type.go +++ b/analysis/type.go @@ -70,7 +70,7 @@ func (a *Analyzer) Analyze(input []byte) TokenStream { return tokens } -var InvalidDateTime = fmt.Errorf("unable to parse datetime with any of the layouts") +var ErrInvalidDateTime = fmt.Errorf("unable to parse datetime with any of the layouts") type DateTimeParser interface { ParseDateTime(string) (time.Time, error) diff --git a/index/upside_down/upside_down.go b/index/upside_down/upside_down.go index 7062aa75..3d5f71e1 100644 --- a/index/upside_down/upside_down.go +++ b/index/upside_down/upside_down.go @@ -22,7 +22,7 @@ import ( "code.google.com/p/goprotobuf/proto" ) -var VersionKey []byte = []byte{'v'} +var VersionKey = []byte{'v'} const Version uint8 = 1 @@ -105,7 +105,7 @@ func (udc *UpsideDownCouch) batchRows(addRows []UpsideDownCouchRow, updateRows [ if err != nil { return err } - tr.freq += 1 // incr + tr.freq++ // incr } else { tr = NewTermFrequencyRow(tfr.term, tfr.field, "", 1, 0) } @@ -136,7 +136,7 @@ func (udc *UpsideDownCouch) batchRows(addRows []UpsideDownCouchRow, updateRows [ if err != nil { return err } - tr.freq -= 1 // incr + tr.freq-- // incr } else { return fmt.Errorf("unexpected missing row, deleting term, expected count row to exist: %v", tr.Key()) } @@ -193,13 +193,13 @@ func (udc *UpsideDownCouch) countDocs() uint64 { it := udc.store.Iterator([]byte{'b'}) defer it.Close() - var rv uint64 = 0 + var rv uint64 key, _, valid := it.Current() for valid { if !bytes.HasPrefix(key, []byte{'b'}) { break } - rv += 1 + rv++ it.Next() key, _, valid = it.Current() } @@ -211,10 +211,10 @@ func (udc *UpsideDownCouch) rowCount() uint64 { it := udc.store.Iterator([]byte{0}) defer it.Close() - var rv uint64 = 0 + var rv uint64 _, _, valid := it.Current() for valid { - rv += 1 + rv++ it.Next() _, _, valid = it.Current() } @@ -243,7 +243,7 @@ func (udc *UpsideDownCouch) Update(doc *document.Document) error { err = udc.batchRows(addRows, updateRows, deleteRows) if err == nil && backIndexRow == nil { - udc.docCount += 1 + udc.docCount++ } return err } @@ -317,7 +317,7 @@ func (udc *UpsideDownCouch) updateSingle(doc *document.Document, backIndexRow *B updateRows = append(updateRows, backIndexRow) // any of the existing rows that weren't updated need to be deleted - for existingTermKey, _ := range existingTermKeys { + for existingTermKey := range existingTermKeys { termFreqRow, err := NewTermFrequencyRowK([]byte(existingTermKey)) if err == nil { deleteRows = append(deleteRows, termFreqRow) @@ -325,7 +325,7 @@ func (udc *UpsideDownCouch) updateSingle(doc *document.Document, backIndexRow *B } // any of the existing stored fields that weren't updated need to be deleted - for existingStoredKey, _ := range existingStoredKeys { + for existingStoredKey := range existingStoredKeys { storedRow, err := NewStoredRowK([]byte(existingStoredKey)) if err == nil { deleteRows = append(deleteRows, storedRow) @@ -440,7 +440,7 @@ func (udc *UpsideDownCouch) Delete(id string) error { err = udc.batchRows(nil, nil, deleteRows) if err == nil { - udc.docCount -= 1 + udc.docCount-- } return err } @@ -485,7 +485,7 @@ func (udc *UpsideDownCouch) backIndexRowsForBatch(batch index.Batch) (map[string // FIXME faster to order the ids and scan sequentially // for now just get it working rv := make(map[string]*BackIndexRow, 0) - for docId, _ := range batch { + for docId := range batch { backIndexRow, err := udc.backIndexRowForDoc(docId) if err != nil { return nil, err diff --git a/index/upside_down/upside_down_test.go b/index/upside_down/upside_down_test.go index cfc63b8e..91555e68 100644 --- a/index/upside_down/upside_down_test.go +++ b/index/upside_down/upside_down_test.go @@ -37,7 +37,7 @@ func TestIndexOpenReopen(t *testing.T) { t.Errorf("error opening index: %v", err) } - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) @@ -78,7 +78,7 @@ func TestIndexInsert(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) @@ -90,7 +90,7 @@ func TestIndexInsert(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ docCount = idx.DocCount() if docCount != expectedCount { @@ -116,7 +116,7 @@ func TestIndexInsertThenDelete(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) @@ -128,7 +128,7 @@ func TestIndexInsertThenDelete(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ doc2 := document.NewDocument("2") doc2.AddField(document.NewTextField("name", []uint64{}, []byte("test"))) @@ -136,7 +136,7 @@ func TestIndexInsertThenDelete(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ docCount = idx.DocCount() if docCount != expectedCount { @@ -147,7 +147,7 @@ func TestIndexInsertThenDelete(t *testing.T) { if err != nil { t.Errorf("Error deleting entry from index: %v", err) } - expectedCount -= 1 + expectedCount-- docCount = idx.DocCount() if docCount != expectedCount { @@ -158,7 +158,7 @@ func TestIndexInsertThenDelete(t *testing.T) { if err != nil { t.Errorf("Error deleting entry from index: %v", err) } - expectedCount -= 1 + expectedCount-- docCount = idx.DocCount() if docCount != expectedCount { @@ -232,7 +232,7 @@ func TestIndexInsertMultiple(t *testing.T) { t.Errorf("error opening index: %v", err) } - var expectedCount uint64 = 0 + var expectedCount uint64 doc := document.NewDocument("1") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test"))) @@ -295,7 +295,7 @@ func TestIndexInsertWithStore(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) @@ -307,7 +307,7 @@ func TestIndexInsertWithStore(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ docCount = idx.DocCount() if docCount != expectedCount { @@ -400,7 +400,7 @@ func TestIndexBatch(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 // first create 2 docs the old fashioned way doc := document.NewDocument("1") @@ -409,7 +409,7 @@ func TestIndexBatch(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ doc = document.NewDocument("2") doc.AddField(document.NewTextField("name", []uint64{}, []byte("test2"))) @@ -417,7 +417,7 @@ func TestIndexBatch(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ // now create a batch which does 3 things // insert new doc @@ -477,7 +477,7 @@ func TestIndexInsertUpdateDeleteWithMultipleTypesStored(t *testing.T) { } defer idx.Close() - var expectedCount uint64 = 0 + var expectedCount uint64 docCount := idx.DocCount() if docCount != expectedCount { t.Errorf("Expected document count to be %d got %d", expectedCount, docCount) @@ -495,7 +495,7 @@ func TestIndexInsertUpdateDeleteWithMultipleTypesStored(t *testing.T) { if err != nil { t.Errorf("Error updating index: %v", err) } - expectedCount += 1 + expectedCount++ docCount = idx.DocCount() if docCount != expectedCount {