# README

Greenbone Logo

paging

import "github.com/greenbone/opensight-golang-libraries/pkg/query/paging"

Index

func AddRequest

func AddRequest(transaction *gorm.DB, request *Request) *gorm.DB

AddRequest adds pagination to the gorm transaction based on the given request.

transaction: The GORM database transaction. request: The request object containing pagination information.

  • PageIndex: The index of the page to retrieve (starting from 0).
  • PageSize: The number of records to retrieve per page.

Returns the modified transaction with the pagination applied.

func NewPagingError

func NewPagingError(format string, value ...any) error

type Error

type Error struct {
    Msg string
}

func (*Error) Error

func (e *Error) Error() string

type PagingSettingsInterface

type PagingSettingsInterface interface {
    GetPagingDefault() (pageSize int)
}

type Request

type Request struct {
    PageIndex int `json:"index"`
    PageSize  int `json:"size"`
}

func ValidateAndApplyPagingRules

func ValidateAndApplyPagingRules(model PagingSettingsInterface, request *Request) (*Request, error)

ValidateAndApplyPagingRules performs a validation of the original request and adds correct the correct values (defaults) if needed

type Response

Response represents a response object containing information about pagination and total count of records.

  • PageIndex: The index of the page (starting from 0). This is required.
  • PageSize: The number of records per page. This is required.
  • TotalDisplayableResults: The total number of results that can be paginated. Due to database restrictions, in case of large number of results, some of the results cannot be retrieved. In such cases, this number will be lower than the `TotalResults`. This is required.
  • TotalResults: The total count of results as it exists in database, including those that may not be retrieved. This is optional and must not be set if the value does not differ from `TotalDisplayableResults`
type Response struct {
    PageIndex               int    `json:"index" binding:"required"`
    PageSize                int    `json:"size" binding:"required"`
    TotalDisplayableResults uint64 `json:"totalDisplayableResults" binding:"required"`
    TotalResults            uint64 `json:"totalResults,omitempty"`
}

func NewResponse

func NewResponse(request *Request, totalDisplayableResults uint64) *Response

func NewResponseWithTotalResults

func NewResponseWithTotalResults(request *Request, totalDisplayableResults, totalResults uint64) *Response

Generated by gomarkdoc

License

Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]

Licensed under the GNU General Public License v3.0 or later.

# Functions

AddRequest adds pagination to the gorm transaction based on the given request.
No description provided by the author
No description provided by the author
No description provided by the author
ValidateAndApplyPagingRules performs a validation of the original request and adds correct the correct values (defaults) if needed.

# Structs

No description provided by the author
No description provided by the author
Response represents a response object containing information about pagination and total count of records.

# Interfaces

No description provided by the author