common

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package common useful functionality for encoding and decoding objects

Index

Constants

View Source
const (
	// Default number of pages
	DefaultPerPage = 20

	// Default page number
	DefaultPage = 1
)

Variables

This section is empty.

Functions

func Contains added in v0.7.0

func Contains[T comparable](collection []T, element T) bool

Contains returns true if an element is present in a collection. Deprecated: use `slice.Contains` which import from `golang.org/x/exp/slices` instead

func FromJSONBase64

func FromJSONBase64(encodeStr string, obj interface{}) error

FromJSONBase64 decode encodeStr using base64, and then use json to convert to obj. Deprecated: use encoding.Base64Decode instead

func Paginate

func Paginate(total, perPage, page int) (begin, end int)

Paginate this function implements the paging of List, inputting the total number of data (usually the length of Slice), the number of each page, and the page number. The function guarantees that Begin and End do not exceed the total number of data.

If input perPage is less than 1, it will be set as DefaultPerPage. If input page is less than 1, it will be set as DefaultPage.

Returns the start and end position of the pagination.

func ToJSONBase64

func ToJSONBase64(obj interface{}) (string, error)

ToJSONBase64 convert obj to json string, and then encode it with base64. Deprecated: use encoding.Base64Encode instead

Types

This section is empty.

Jump to

Keyboard shortcuts

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