responses

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package responses contains helper functions to create response that can be returned by the application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InfiniteScrollLinks struct {
	Next string `json:"next" example:"http://localhost:8080?cursor=2021-08-01&limit=10"`
}

type InfiniteScrollMeta

type InfiniteScrollMeta struct {
	Total int `json:"total" example:"100"`
}

type InfiniteScrollResponse

type InfiniteScrollResponse[T any] struct {
	Code    int                 `json:"code" example:"123"`
	Message string              `json:"message"`
	Links   InfiniteScrollLinks `json:"links"`
	Meta    InfiniteScrollMeta  `json:"meta"`
	Data    []T                 `json:"data"`
}

InfiniteScrollResponse is a struct that contains the response of infinite scroll

This response can be used to return the result of infinite scroll by using the following code:

var result InfiniteScrollResult[User]
ctx.JSON(result.GetInfiniteScrollResponse(urlConfig, limit))

type InfiniteScrollResult

type InfiniteScrollResult[T any] struct {
	NextCursor string
	Data       []T
	Total      int
}

InfiniteScrollResult is a struct that contains the result of infinite scroll from the database using query object

func (*InfiniteScrollResult[T]) GetInfiniteScrollResponse

func (r *InfiniteScrollResult[T]) GetInfiniteScrollResponse(urlConfig UrlConfig, limit int) InfiniteScrollResponse[T]

GetInfiniteScrollResponse is a function to create InfiniteScrollResponse from InfiniteScrollResult

func (*InfiniteScrollResult[T]) GetResponseByBaseUrl added in v1.5.3

func (r *InfiniteScrollResult[T]) GetResponseByBaseUrl(baseUrl string, limit int) InfiniteScrollResponse[T]
type TableAdvancedLinks struct {
	Next string `json:"next" example:"http://localhost:8080?start_after=2021-08-01&page=3"`
	Prev string `json:"prev" example:"http://localhost:8080?end_before=2021-08-01&page=1"`
}

type TableAdvancedMeta

type TableAdvancedMeta struct {
	Total int `json:"total" example:"100"`
	Range int `json:"range" example:"10"`
	Page  int `json:"page" example:"2"`
}

type TableAdvancedResponse

type TableAdvancedResponse[T any] struct {
	Code    int                `json:"code" example:"123"`
	Message string             `json:"message"`
	Links   TableAdvancedLinks `json:"links"`
	Meta    TableAdvancedMeta  `json:"meta"`
	Data    []T                `json:"data"`
}

TableAdvancedResponse is a struct that contains the response of table advanced

This response can be used to return the result of table advanced by using the following code:

var result TableAdvancedResult[User]
ctx.JSON(result.GetTableAdvancedResponse(urlConfig, limit, currentPage))

type TableAdvancedResult

type TableAdvancedResult[T any] struct {
	StartAfter string
	EndBefore  string
	Data       []T
	Total      int
	ItemCount  int
}

TableAdvancedResult is a struct that contains the result of table advanced from the database using query object

func (*TableAdvancedResult[T]) GetTableAdvancedResponse

func (r *TableAdvancedResult[T]) GetTableAdvancedResponse(urlConfig UrlConfig, limit int, currentPage int) TableAdvancedResponse[T]

type UrlConfig

type UrlConfig struct {
	Tls   *tls.ConnectionState
	Host  string
	Path  string
	Query url.Values
}

func (*UrlConfig) FullUrl

func (c *UrlConfig) FullUrl() string

FullUrl is a function to get the full url from UrlConfig

Jump to

Keyboard shortcuts

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