common

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 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

func AbsInt32(v int32) int32

AbsInt32 abs(v)

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

func AbsInt64

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

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

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

Max return the maximal value

func Min

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

Min return the minimal value

func Number2Roman

func Number2Roman(n int) (roman string)

Number2Roman convert number to roman

func Round

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

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

Number is a number type

type SortOrder

type SortOrder int

SortOrder sort order

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

type Sortable

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