tomato

package module
v0.0.0-...-c81791a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 2 Imported by: 0

README

tomato

Pagination package for GO

How to use

package main

import (
    "fmt"
    "os"

    "github.com/NasSilverBullet/tomato"
)

type User struct {
    ID   int
    Name string
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintf(os.Stderr, "[ERROR] %v\n", err)
        os.Exit(1)
    }
}

func run() error {
    us := []User{
        User{1, "nas"},
        User{2, "tomato"},
        User{3, "cucumber"},
        User{4, "green pepper"},
        User{5, "potato"},
    }

    p, err := tomato.New(
        /* current page number: */            2,
        /* amount of records for one page: */ 2,
        /* amount of records: */              len(us),
    )
    if err != nil {
        return err
    }

    currntPageUsersInterface, err := p.FilterCurrent(us)
    if err != nil {
        return err
    }

    for _, u := range currntPageUsersInterface.([]User) {
        fmt.Printf("ID: %d => Name: %s\n", u.ID, u.Name)
        //ID: 3 => Name: cucumber
        //ID: 4 => Name: green pepper
    }

    return nil
}

License

MIT License. See LICENSE.txt for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pagination

type Pagination interface {
	GetCount() int
	GetPer() int
	GetCurrent() int
	GetFirst() int
	GetLast() int
	GetPrevious() int
	GetNext() int
	FilterCurrent(i interface{}) (interface{}, error)
}

func New

func New(current, per, count int) (Pagination, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL