gitlab.com/evatix-go/core@v1.3.55/defaultcapacity/MaxLimit.go (about)

     1  package defaultcapacity
     2  
     3  import "gitlab.com/evatix-go/core/constants"
     4  
     5  // MaxLimit
     6  //
     7  // returns
     8  //  - limit:   -1, returns predictive length based on wholeLength (max 100)
     9  //  - limit: >= 0, returns limit if limit < wholeLength or
    10  //          else returns wholeLength
    11  func MaxLimit(wholeLength int, limit int) int {
    12  	hasLimit := limit > constants.MinusOne
    13  
    14  	if hasLimit && limit >= wholeLength {
    15  		return wholeLength
    16  	} else if hasLimit && limit < wholeLength {
    17  		return limit
    18  	}
    19  
    20  	// no limit
    21  	return wholeLength
    22  }