diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 1efcb602b..1cf560bcb 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -37,32 +37,6 @@ type Paginator struct { Offset *int // Offset of the first item returned (eg: use Limit*Page in case of PerPage items) } -func (pgnt *Paginator) PaginateStringSlice(in []string) (out []string) { - if len(in) == 0 { - return - } - var limit, offset int - if pgnt.Limit != nil && *pgnt.Limit > 0 { - limit = *pgnt.Limit - } - if pgnt.Offset != nil && *pgnt.Offset > 0 { - offset = *pgnt.Offset - } - if limit == 0 && offset == 0 { - return in - } - if offset > len(in) { - return - } - if offset != 0 && limit != 0 { - limit = limit + offset - } - if limit == 0 || limit > len(in) { - limit = len(in) - } - return CloneStringSlice(in[offset:limit]) -} - func GetPaginateOpts(opts map[string]interface{}) (limit, offset, maxItems int, err error) { if limitIface, has := opts[PageLimitOpt]; has { if limit, err = IfaceAsTInt(limitIface); err != nil { diff --git a/utils/apitpdata_test.go b/utils/apitpdata_test.go index ebed65060..2feaaeffc 100644 --- a/utils/apitpdata_test.go +++ b/utils/apitpdata_test.go @@ -23,59 +23,6 @@ import ( "time" ) -func TestPaginatorPaginateStringSlice(t *testing.T) { - //len(in)=0 - eOut := []string{} - pgnt := new(Paginator) - rcv := pgnt.PaginateStringSlice(eOut) - if len(rcv) != 0 { - t.Errorf("Expecting an empty slice, received: %+v", rcv) - } - //offset > len(in) - eOut = []string{"1"} - pgnt = &Paginator{Offset: IntPointer(2), Limit: IntPointer(0)} - rcv = pgnt.PaginateStringSlice(eOut) - - if len(rcv) != 0 { - t.Errorf("Expecting an empty slice, received: %+v", rcv) - } - //offset != 0 && limit != 0 - eOut = []string{"3", "4"} - pgnt = &Paginator{Offset: IntPointer(2), Limit: IntPointer(0)} - rcv = pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}) - - if !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting an empty slice, received: %+v", rcv) - } - - eOut = []string{"1", "2", "3", "4"} - pgnt = new(Paginator) - if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - eOut = []string{"1", "2", "3"} - pgnt.Limit = IntPointer(3) - if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - eOut = []string{"2", "3", "4"} - pgnt.Offset = IntPointer(1) - if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - eOut = []string{} - pgnt.Offset = IntPointer(4) - if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } - eOut = []string{"3"} - pgnt.Offset = IntPointer(2) - pgnt.Limit = IntPointer(1) - if rcv := pgnt.PaginateStringSlice([]string{"1", "2", "3", "4"}); !reflect.DeepEqual(eOut, rcv) { - t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) - } -} - func TestClonePaginator(t *testing.T) { expectedPaginator := Paginator{ Limit: IntPointer(2), diff --git a/utils/coreutils.go b/utils/coreutils.go index 7695bb256..1d7eaf9ac 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -699,12 +699,6 @@ type ArgsItemIDs struct { ItemsPrefix string } -type PaginatorWithTenant struct { - Tenant string - Paginator - APIOpts map[string]interface{} -} - type TenantWithAPIOpts struct { Tenant string APIOpts map[string]interface{}