GithubHelp home page GithubHelp logo

pupilcc / paging Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5 KB

Paging is a simple Go package that helps you manage pagination in your projects.

License: MIT License

Go 98.53% Makefile 1.47%

paging's Introduction

paging

Paging is a simple Go package that helps you manage pagination in your projects. It provides an easy-to-use interface to handle page indexing, page size, total items, and the items themselves.

Features

  • Calculate the total number of pages based on total items and page size.
  • Store pagination details such as current page index, page size, total pages, and total items.
  • Easily integrate with your data models.

Installation

To install the package, you can use go get:

go get github.com/pupilcc/paging

Usage

Below is an example of how to use the Paginator in your Go project:

package main

import (
    "fmt"
    "github.com/pupilcc/paging"
)

func main() {
    // Example data
    items := []string{"item1", "item2", "item3", "item4", "item5"}
    totalItems := len(items)
    pageIndex := 1
    pageSize := 2

    // Create a new Paginator
    paginator := paging.NewPaginator(pageIndex, pageSize, totalItems, items)

    // Print pagination details
    fmt.Printf("Page Index: %d\n", paginator.PageIndex)
    fmt.Printf("Page Size: %d\n", paginator.PageSize)
    fmt.Printf("Total Pages: %d\n", paginator.Pages)
    fmt.Printf("Total Items: %d\n", paginator.Total)
    fmt.Printf("Items: %v\n", paginator.Items)
}

Paginator Struct

The Paginator struct contains the following fields:

  • PageIndex: The current page index.
  • PageSize: The number of items per page.
  • Pages: The total number of pages.
  • Total: The total number of items.
  • Items: The items for the current page.

Functions

NewPaginator

Creates a new Paginator instance.

func NewPaginator(pageIndex, pageSize, total int, items interface{}) *Paginator
  • pageIndex: The current page index.
  • pageSize: The number of items per page.
  • total: The total number of items.
  • items: The items for the current page.

getPages

Calculates the total number of pages.

func getPages(total, pageSize int) int
  • total: The total number of items.
  • pageSize: The number of items per page.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Please feel free to submit issues, fork the repository and send pull requests!

Acknowledgements

This project was inspired by the need for a simple and efficient pagination solution in Go.


Happy coding!

paging's People

Contributors

pupilcc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.