common

package
v4.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package common global shared utils

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt32 added in v4.7.1

func AbsInt32(v int32) int32

AbsInt32 abs(v)

ignore int exceeds limit error, abs(MinInt32) == MaxInt32

func AbsInt64 added in v4.7.1

func AbsInt64(v int64) int64

AbsInt64 abs(v)

ignore int exceeds limit error, abs(MinInt64) == MaxInt64

func Bytes2Str

func Bytes2Str(b []byte) string

Bytes2Str unsafe convert bytes to str

func HumanReadableByteCount added in v4.7.1

func HumanReadableByteCount(bytes int64, si bool) (ret string)

HumanReadableByteCount convert bytes to human readable string

Args:

  • bytes:
  • si: `si ? 1024 : 1000`

Example:

`HumanReadableByteCount(1005, false) -> "1.01KB"`

func Max added in v4.7.1

func Max[T Sortable](vals ...T) T

Max return the maximal value

func Min added in v4.7.1

func Min[T Sortable](vals ...T) T

Min return the minimal value

func Number2Roman added in v4.7.3

func Number2Roman(n int) (roman string)

Number2Roman convert number to roman

func Round added in v4.7.1

func Round(val float64, d int) float64

Round round float64

Round(1.005, 2) -> 1.01

func Str2Bytes

func Str2Bytes(s string) []byte

Str2Bytes unsafe convert str to bytes

Types

type Number added in v4.7.1

type Number interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float32 | float64
}

Number is a number type

type SortOrder added in v4.7.1

type SortOrder int

SortOrder sort order

const (
	// SortOrderAsc asc
	SortOrderAsc SortOrder = iota
	// SortOrderDesc desc
	SortOrderDesc
)

type Sortable added in v4.7.1

type Sortable interface {
	Number | string
}

Sortable Data types that can be compared by >, <, ==

Jump to

Keyboard shortcuts

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