paging

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: GPL-3.0 Imports: 2 Imported by: 4

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, totalResults, resultLimit 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

Types

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

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"`
}

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`

func NewResponse

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

func NewResponseWithTotalResults added in v1.8.0

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

Jump to

Keyboard shortcuts

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