tools

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: MIT Imports: 13 Imported by: 0

README

类: Pagination: 分页工具 JSONMarshalString: Marshal JSON

Documentation

Overview

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2016-2023 chad.wang<chad.wang@icloudsky.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2016-2023 volibear<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.

Package tools Copyright 2016-2023 chad.wang<chad.wang@icloudsky.com>. All rights reserved.

Index

Constants

View Source
const (
	// RandomLowercase lowercase
	RandomLowercase randomType = 2 << iota
	// RandomMajuscule majuscule
	RandomMajuscule
	// RandomDigital digital
	RandomDigital
	// RandomSymbol symbol
	RandomSymbol
	// RandomAll all
	RandomAll = RandomLowercase | RandomMajuscule | RandomDigital | RandomSymbol
)
View Source
const IsDarwin = false
View Source
const IsLinux = true
View Source
const IsWindows = false
View Source
const TimeFormatString = "2006-01-02 15:04:05"

TimeFormatString time layout

Variables

This section is empty.

Functions

func Close

func Close(f io.Closer)

Close fast ptr close when use defer close, it's shortcut

func FormatTime

func FormatTime[T constraints.Float | constraints.Integer](sec T, nsec T) string

FormatTime format time use TimeFormatString layout

func GetCurrentDirectory

func GetCurrentDirectory() string

GetCurrentDirectory return current execute file directory

func IsNumber

func IsNumber(s string) bool

IsNumber check string is number?

func JSONMarshalByte

func JSONMarshalByte(v interface{}) []byte

JSONMarshalByte ignore error, return JSON.Marshal []byte()

func JSONMarshalString

func JSONMarshalString(v interface{}) string

JSONMarshalString ignore error,return JSON.Marshal string

func Md5

func Md5(s string) string

Md5 calculator md5 string

func Md5File

func Md5File(filePath string) (string, error)

Md5File calculator file md5 string

func PathExists

func PathExists(path string) (bool, error)

PathExists check path

func RandomString

func RandomString(length uint, charType randomType) (s string)

RandomString random a string

func RemoveSameFromStringSlice

func RemoveSameFromStringSlice(slice []string) []string

RemoveSameFromStringSlice remove []string same element Deprecated: use SliceTrimSame replace

func ReverseByte

func ReverseByte(s []byte) []byte

ReverseByte reverse []byte

func SliceRemove

func SliceRemove[T comparable](remove []T, s []T) []T

SliceRemove remove value

func SliceTrimSame

func SliceTrimSame[T comparable](s []T) []T

SliceTrimSame remove same value

func XMLMarshalByte added in v0.0.6

func XMLMarshalByte(v interface{}) []byte

XMLMarshalByte ignore error, return xml.Marshal []byte()

func XMLMarshalString added in v0.0.6

func XMLMarshalString(v interface{}) string

XMLMarshalString ignore error,return xml.Marshal string

Types

type PaginationData

type PaginationData struct {
	Total        int64   // total record
	Page         int64   // current page
	PageSize     int64   // show size every page
	PageNums     int64   // show digital numbers on page
	FirstPage    int64   // first page
	LastPage     int64   // last page
	PreviousPage int64   // previous page
	NextPage     int64   // next page
	TotalPage    int64   // total page
	Pages        []int64 // pages
}

PaginationData pagination data

func Pagination

func Pagination(total, page, pageSize int64, pageNum int64) (pg *PaginationData)

Pagination calculate total record page current page pageSize show size every page pagesNum show digital numbers on page

type TSMap added in v0.0.7

type TSMap[K, T any] struct {
	// contains filtered or unexported fields
}

TSMap thread safe map

func (*TSMap[K, T]) Len added in v0.0.7

func (m *TSMap[K, T]) Len() int64

func (*TSMap[K, T]) Load added in v0.0.7

func (m *TSMap[K, T]) Load(key K) (T, bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*TSMap[K, T]) LoadAndDelete added in v0.0.7

func (m *TSMap[K, T]) LoadAndDelete(key K) (T, bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*TSMap[K, T]) LoadOrStore added in v0.0.7

func (m *TSMap[K, T]) LoadOrStore(key K, value T) (T, bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*TSMap[K, T]) Range added in v0.0.7

func (m *TSMap[K, T]) Range(f func(key K, value T) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*TSMap[K, T]) Store added in v0.0.7

func (m *TSMap[K, T]) Store(key K, value T)

Jump to

Keyboard shortcuts

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