PageRange returns start and end indices given pagination params. Note that n is the size of the input list.
(count, offset, n int)
| 736 | // PageRange returns start and end indices given pagination params. Note that n |
| 737 | // is the size of the input list. |
| 738 | func PageRange(count, offset, n int) (int, int) { |
| 739 | if n == 0 { |
| 740 | return 0, 0 |
| 741 | } |
| 742 | if count == 0 && offset == 0 { |
| 743 | return 0, n |
| 744 | } |
| 745 | if count < 0 { |
| 746 | // Items from the back of the array, like Python arrays. Do a positive mod n. |
| 747 | if count*-1 > n { |
| 748 | count = -n |
| 749 | } |
| 750 | return (((n + count) % n) + n) % n, n |
| 751 | } |
| 752 | start := offset |
| 753 | if start < 0 { |
| 754 | start = 0 |
| 755 | } |
| 756 | if start > n { |
| 757 | return n, n |
| 758 | } |
| 759 | if count == 0 { // No count specified. Just take the offset parameter. |
| 760 | return start, n |
| 761 | } |
| 762 | end := start + count |
| 763 | if end > n { |
| 764 | end = n |
| 765 | } |
| 766 | return start, end |
| 767 | } |
| 768 | |
| 769 | // ValidateAddress checks whether given address can be used with grpc dial function |
| 770 | func ValidateAddress(addr string) error { |
no outgoing calls
no test coverage detected