xo

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 21 Imported by: 2

README ΒΆ

xo

Go Reference

πŸͺ Universal external Golang utilities, implementations, and even experimental coding patterns, designs

🀠 Spec

GoDoc: https://godoc.org/github.com/nekomeowww/xo

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	UnitBytesOfTB = 1000 * UnitBytesOfGB
	UnitBytesOfGB = 1000 * UnitBytesOfMB
	UnitBytesOfMB = 1000 * UnitBytesOfKB
	UnitBytesOfKB = 1000

	UnitBytesOfTiB = 1024 * UnitBytesOfGiB
	UnitBytesOfGiB = 1024 * UnitBytesOfMiB
	UnitBytesOfMiB = 1024 * UnitBytesOfKiB
	UnitBytesOfKiB = 1024
)

Variables ΒΆ

View Source
var (
	UnitSecondsOfMonth  = 30 * UnitSecondsOfDay
	UnitSecondsOfDay    = 24 * UnitSecondsOfHour
	UnitSecondsOfHour   = 60 * UnitSecondsOfMinute
	UnitSecondsOfMinute = 60 * time.Second
)

Functions ΒΆ

func ContainsCJKChar ΒΆ

func ContainsCJKChar(s string) bool

ContainsCJKChar determines whether a string contains CJK characters.

func ConvertUint64ToDecimalString ΒΆ

func ConvertUint64ToDecimalString(amount uint64, prec int) string

ConvertUint64ToDecimalString formats a uint64 to a string with a decimal point.

func DigitOf ΒΆ

func DigitOf[I uint | uint16 | uint32 | uint64 | int | int16 | int32 | int64](val I, n int) I

DigitOf returns the n-th digit of val.

Underlying calculation is based on (val % 10^n) .

func FindDuplicates ΒΆ

func FindDuplicates[T comparable](a []T) []T

FindDuplicates returns a new slice contains items that are duplicated in a.

func Intersection ΒΆ

func Intersection[T comparable](a, b []T) []T

Intersection returns a new slice contains items that are in both a and b.

func IsASCIIPrintable ΒΆ

func IsASCIIPrintable(s string) bool

IsASCIIPrintable determines whether a string is printable ASCII.

func IsDecimalsPlacesValid ΒΆ

func IsDecimalsPlacesValid(num float64, decimalPlaces int) bool

func IsInTestEnvironment ΒΆ

func IsInTestEnvironment() bool

IsInTestEnvironment determines whether the current environment is a test environment.

func IsJSON ΒΆ

func IsJSON(str string) bool

IsJSON determines whether the string is JSON.

func IsJSONBytes ΒΆ

func IsJSONBytes(bytes []byte) bool

IsJSONBytes determines whether the bytes is JSON.

func IsStringPrintable ΒΆ

func IsStringPrintable(str string) bool

IsStringPrintable determines whether a string is printable.

func IsValidUUID ΒΆ

func IsValidUUID(uuidStr string) bool

IsValidUUID determines whether a string is a valid UUID.

func Join ΒΆ

func Join[T any](from []T, sep string) string

Join returns a string contains items joined with sep by using fmt.Sprintf.

func JoinWithConverter ΒΆ

func JoinWithConverter[T any](from []T, sep string, convertFunc func(item T) string) string

JoinWithConverter returns a string contains converted items joined with sep.

func ParseUint64FromDecimalString ΒΆ

func ParseUint64FromDecimalString(decimalStr string, percision int) (uint64, error)

ParseUint64FromDecimalString converts a string with a decimal point to a uint64.

func Print ΒΆ

func Print(inputs ...interface{})

Print formats the output of all incoming values in terms of field, value, type, and size.

func PrintJSON ΒΆ

func PrintJSON(inputs ...interface{})

PrintJSON formats the output of all incoming values in JSON format.

func RandBytes ΒΆ

func RandBytes(length ...int) ([]byte, error)

RandBytes generates bytes according to the given length, defaults to 32.

func RandomBase64Token ΒΆ

func RandomBase64Token(length ...int) (string, error)

RandomBase64Token generates the URL-safe Base64 string based on the given byte length, the length is 32 by default, the length is the length of the original byte data, not the actual length of the Base64 string, the actual length is about 44 by default in the case of 32.

func RandomHashString ΒΆ

func RandomHashString(length ...int) string

RandomHashString generates a random SHA256 string with the maximum length of 64.

func RandomInt64 ΒΆ

func RandomInt64(max ...int64) int64

RandomInt64 generates a random integer.

func RandomInt64InRange ΒΆ

func RandomInt64InRange(min, max int64) int64

RandomInt64InRange generates a random integer in the range.

func RandomInt64String ΒΆ

func RandomInt64String(digits int64) string

RandomInt64String generates a random integer string.

func ReadFileAsBytesBuffer ΒΆ

func ReadFileAsBytesBuffer(path string) (*bytes.Buffer, error)

ReadFileAsBytesBuffer reads a file and returns a bytes.Buffer.

func RelativePathBasedOnPwdOf ΒΆ

func RelativePathBasedOnPwdOf(fp string) string

func RelativePathOf ΒΆ

func RelativePathOf(fp string) string

func SliceSlices ΒΆ

func SliceSlices[T any](from []T, each int) [][]T

SliceSlices returns a new slice contains slices with maximum length each.

func Sprint ΒΆ

func Sprint(inputs ...interface{}) string

Sprint formats the output of all the fields, values, types, and sizes of the values passed in and returns the string.

NOTICE: newline control character is included.

func SprintJSON ΒΆ

func SprintJSON(inputs ...interface{}) string

SprintJSON formats the output of all incoming values in JSON format and

NOTICE: newline control character is included.

func ToMap ΒΆ

func ToMap[T any, K comparable](t []T, keyGetter func(T) K) map[K]T

ToMap converts a slice to a map with key from key getter func and pairs with value.

Types ΒΆ

type EmptyIoReader ΒΆ added in v1.3.0

type EmptyIoReader = NopIoReader

type EmptyIoWriter ΒΆ added in v1.3.0

type EmptyIoWriter = NopIoWriter

type NopIoReader ΒΆ added in v1.3.0

type NopIoReader struct{}

func NewEmptyIoReader ΒΆ added in v1.3.0

func NewEmptyIoReader() *NopIoReader

func NewNopIoReader ΒΆ added in v1.3.0

func NewNopIoReader() *NopIoReader

func (*NopIoReader) Read ΒΆ added in v1.3.0

func (r *NopIoReader) Read(p []byte) (n int, err error)

type NopIoWriter ΒΆ added in v1.3.0

type NopIoWriter struct{}

func NewEmptyIoWriter ΒΆ added in v1.3.0

func NewEmptyIoWriter() *NopIoWriter

func NewNopIoWriter ΒΆ added in v1.3.0

func NewNopIoWriter() *NopIoWriter

func (*NopIoWriter) Write ΒΆ added in v1.3.0

func (w *NopIoWriter) Write(p []byte) (n int, err error)

Directories ΒΆ

Path Synopsis
exp
Package logger ζ—₯εΏ—εŒ…οΌŒη”¨δΊŽζ—₯εΏ—θΎ“ε‡Ίε’Œζ‰“ε°
Package logger ζ—₯εΏ—εŒ…οΌŒη”¨δΊŽζ—₯εΏ—θΎ“ε‡Ίε’Œζ‰“ε°

Jump to

Keyboard shortcuts

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