storj/satellite/metabase/util.go

34 lines
751 B
Go
Raw Permalink Normal View History

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase
import (
"github.com/zeebo/errs"
"storj.io/private/tagsql"
)
func withRows(rows tagsql.Rows, err error) func(func(tagsql.Rows) error) error {
return func(callback func(tagsql.Rows) error) error {
if err != nil {
return err
}
err := callback(rows)
return errs.Combine(rows.Err(), rows.Close(), err)
}
}
// intLimitRange defines a valid range (1,limit].
type intLimitRange int
// Ensure clamps v to a value between [1,limit].
func (limit intLimitRange) Ensure(v *int) {
if *v <= 0 || *v > int(limit) {
*v = int(limit)
}
}
// Max returns maximum value for the given range.
func (limit intLimitRange) Max() int { return int(limit) }