Fix linter issues: nakedret

This commit is contained in:
Cody Soyland 2018-07-18 15:23:36 -05:00
parent cceb1ebdf6
commit 2aa4d6b12f
9 changed files with 73 additions and 54 deletions

View file

@ -119,6 +119,7 @@ gometalinter: require-gometalinter
--enable=gotypex \
--enable=interfacer \
--enable=misspell \
--enable=nakedret \
--enable=unparam \
--exclude "^internal/.*\.pb\.go" \
--exclude "^pql/pql.peg.go" \

View file

@ -120,17 +120,20 @@ func (s *attrStore) Close() error {
}
// Attrs returns a set of attributes by ID.
func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
func (s *attrStore) Attrs(id uint64) (map[string]interface{}, error) {
s.mu.RLock()
defer s.mu.RUnlock()
var m map[string]interface{}
// Check cache for map.
if m = s.attrCache.Get(id); m != nil {
return m, nil
}
// Find attributes from storage.
if err = s.db.View(func(tx *bolt.Tx) error {
if err := s.db.View(func(tx *bolt.Tx) error {
var err error
m, err = txAttrs(tx, id)
if err != nil {
return err
@ -143,7 +146,7 @@ func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
// Add to cache.
s.attrCache.Set(id, m)
return
return m, nil
}
// SetAttrs sets attribute values for a given ID.

View file

@ -193,7 +193,8 @@ func (q *x) insert(i int, k uint64, ch interface{}) *x {
return q
}
func (q *x) siblings(i int) (l, r *d) {
func (q *x) siblings(i int) (*d, *d) {
var l, r *d
if i >= 0 {
if i > 0 {
l = q.x[i-1].ch.(*d)
@ -202,7 +203,7 @@ func (q *x) siblings(i int) (l, r *d) {
r = q.x[i+1].ch.(*d)
}
}
return
return l, r
}
// -------------------------------------------------------------------------- d
@ -419,12 +420,14 @@ func (t *tree) find(q interface{}, k uint64) (i int, ok bool) {
// First returns the first item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func (t *tree) First() (k uint64, v *roaring.Container) {
func (t *tree) First() (uint64, *roaring.Container) {
var k uint64
var v *roaring.Container
if q := t.first; q != nil {
q := &q.d[0]
k, v = q.k, q.v
}
return
return k, v
}
// Get returns the value associated with k and true if it exists. Otherwise Get
@ -470,12 +473,14 @@ func (t *tree) insert(q *d, i int, k uint64, v *roaring.Container) *d {
// Last returns the last item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func (t *tree) Last() (k uint64, v *roaring.Container) {
func (t *tree) Last() (uint64, *roaring.Container) {
var k uint64
var v *roaring.Container
if q := t.last; q != nil {
q := &q.d[q.c-1]
k, v = q.k, q.v
}
return
return k, v
}
// Len returns the number of items in the tree.
@ -858,9 +863,12 @@ func (e *enumerator) Close() {
// Next returns the currently enumerated item, if it exists and moves to the
// next item in the key collation order. If there is no item to return, err ==
// io.EOF is returned.
func (e *enumerator) Next() (k uint64, v *roaring.Container, err error) {
func (e *enumerator) Next() (uint64, *roaring.Container, error) {
var k uint64
var v *roaring.Container
var err error
if err = e.err; err != nil {
return
return 0, nil, err
}
if e.ver != e.t.ver {
@ -870,12 +878,12 @@ func (e *enumerator) Next() (k uint64, v *roaring.Container, err error) {
}
if e.q == nil {
e.err, err = io.EOF, io.EOF
return
return 0, nil, err
}
if e.i >= e.q.c {
if err = e.next(); err != nil {
return
return 0, nil, err
}
}
@ -883,7 +891,7 @@ func (e *enumerator) Next() (k uint64, v *roaring.Container, err error) {
k, v = i.k, i.v
e.k, e.hit = k, true
e.next()
return
return k, v, nil
}
func (e *enumerator) next() error {
@ -906,9 +914,13 @@ func (e *enumerator) next() error {
// Prev returns the currently enumerated item, if it exists and moves to the
// previous item in the key collation order. If there is no item to return, err
// == io.EOF is returned.
func (e *enumerator) Prev() (k uint64, v *roaring.Container, err error) {
func (e *enumerator) Prev() (uint64, *roaring.Container, error) {
var k uint64
var v *roaring.Container
var err error
if err = e.err; err != nil {
return
return 0, nil, err
}
if e.ver != e.t.ver {
@ -918,19 +930,19 @@ func (e *enumerator) Prev() (k uint64, v *roaring.Container, err error) {
}
if e.q == nil {
e.err, err = io.EOF, io.EOF
return
return 0, nil, err
}
if !e.hit {
// move to previous because Seek overshoots if there's no hit
if err = e.prev(); err != nil {
return
return 0, nil, err
}
}
if e.i >= e.q.c {
if err = e.prev(); err != nil {
return
return 0, nil, err
}
}
@ -938,7 +950,7 @@ func (e *enumerator) Prev() (k uint64, v *roaring.Container, err error) {
k, v = i.k, i.v
e.k, e.hit = k, true
e.prev()
return
return k, v, err
}
func (e *enumerator) prev() error {

View file

@ -121,14 +121,15 @@ func (btc *bTreeContainers) GetOrCreate(key uint64) *roaring.Container {
return btc.lastContainer
}
func (btc *bTreeContainers) Count() (n uint64) {
func (btc *bTreeContainers) Count() uint64 {
var n uint64
e, _ := btc.tree.Seek(0)
_, c, err := e.Next()
for err != io.EOF {
n += uint64(c.N())
_, c, err = e.Next()
}
return
return n
}
func (btc *bTreeContainers) Clone() roaring.Containers {

View file

@ -796,8 +796,8 @@ func groupCompare(a, b string, offset int) (lt, eq bool) {
return v < 0, v == 0
}
func (f *Field) allTimeViewsSortedByQuantum() (me []*view) {
me = make([]*view, len(f.viewMap), len(f.viewMap))
func (f *Field) allTimeViewsSortedByQuantum() []*view {
me := make([]*view, len(f.viewMap), len(f.viewMap))
prefix := viewStandard + "_"
offset := len(viewStandard) + 1
i := 0
@ -811,8 +811,8 @@ func (f *Field) allTimeViewsSortedByQuantum() (me []*view) {
year := strings.Index(me[0].name, "_") + 4
month := year + 2
day := month + 2
sort.Slice(me, func(i, j int) (lt bool) {
var eq bool
sort.Slice(me, func(i, j int) bool {
var eq, lt bool
// group by quantum from year to hour
if lt, eq = groupCompare(me[i].name, me[j].name, year); eq {
if lt, eq = groupCompare(me[i].name, me[j].name, month); eq {
@ -821,9 +821,9 @@ func (f *Field) allTimeViewsSortedByQuantum() (me []*view) {
}
}
}
return
return lt
})
return
return me
}
// Value reads a field value for a column.

View file

@ -1162,15 +1162,16 @@ func (f *fragment) readContiguousChecksums(a *[]FragmentBlock, blockID int) (n i
}
// blockData returns bits in a block as row & column ID pairs.
func (f *fragment) blockData(id int) (rowIDs, columnIDs []uint64) {
func (f *fragment) blockData(id int) ([]uint64, []uint64) {
f.mu.Lock()
defer f.mu.Unlock()
rowIDs := make([]uint64, 0)
columnIDs := make([]uint64, 0)
f.storage.ForEachRange(uint64(id)*HashBlockSize*ShardWidth, (uint64(id)+1)*HashBlockSize*ShardWidth, func(i uint64) {
rowIDs = append(rowIDs, i/ShardWidth)
columnIDs = append(columnIDs, i%ShardWidth)
})
return
return rowIDs, columnIDs
}
// mergeBlock compares the block's bits and computes a diff with another set of block bits.
@ -1965,12 +1966,12 @@ func (s *fragmentSyncer) syncBlock(id int) error {
return nil
}
func madvise(b []byte, advice int) (err error) { // nolint: unparam
_, _, e1 := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
if e1 != 0 {
err = e1
func madvise(b []byte, advice int) error { // nolint: unparam
_, _, err := syscall.Syscall(syscall.SYS_MADVISE, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), uintptr(advice))
if err != 0 {
return err
}
return
return nil
}
// pairSet is a list of equal length row and column id lists.

View file

@ -299,10 +299,12 @@ type successResponse struct {
// check determines success or failure based on the error.
// It also returns the corresponding http status code.
func (r *successResponse) check(err error) (statusCode int) {
func (r *successResponse) check(err error) int {
var statusCode int
if err == nil {
r.Success = true
return
return 0
}
cause := errors.Cause(err)
@ -322,7 +324,7 @@ func (r *successResponse) check(err error) (statusCode int) {
r.Success = false
r.Error = &Error{Message: cause.Error()}
return
return statusCode
}
// write sends a response to the http.ResponseWriter based on the success

View file

@ -71,15 +71,15 @@ func (c *Cache) Add(key Key, value interface{}) {
}
// Get looks up a key's value from the cache.
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
func (c *Cache) Get(key Key) (interface{}, bool) {
if c.cache == nil {
return
return nil, false
}
if ele, hit := c.cache[key]; hit {
c.ll.MoveToFront(ele)
return ele.Value.(*entry).value, true
}
return
return nil, false
}
// remove removes the provided key from the cache.

View file

@ -1895,7 +1895,8 @@ func intersectionCountArrayRun(a, b *Container) (n int) {
return n
}
func intersectionCountRunRun(a, b *Container) (n int) {
func intersectionCountRunRun(a, b *Container) int {
var n int
na, nb := len(a.runs), len(b.runs)
for i, j := 0, 0; i < na && j < nb; {
va, vb := a.runs[i], b.runs[j]
@ -1923,7 +1924,7 @@ func intersectionCountRunRun(a, b *Container) (n int) {
i++
}
}
return
return n
}
func intersectionCountBitmapRun(a, b *Container) (n int) {
@ -3144,22 +3145,20 @@ func xorArrayRun(a, b *Container) *Container {
}
// xorCompare computes first exclusive run between two runs.
func xorCompare(x *xorstm) (r1 interval16, hasData bool) {
hasData = false
func xorCompare(x *xorstm) (interval16, bool) {
var r1 interval16
var hasData bool
if !x.vaValid || !x.vbValid {
if x.vbValid {
x.vbValid = false
r1 = x.vb
hasData = true
return
return x.vb, true
}
if x.vaValid {
x.vaValid = false
r1 = x.va
hasData = true
return
return x.va, true
}
return
return r1, false
}
if x.va.last < x.vb.start { //va before
@ -3232,7 +3231,7 @@ func xorCompare(x *xorstm) (r1 interval16, hasData bool) {
}
}
}
return
return r1, hasData
}
//stm is state machine used to "xor" iterate over runs.