typeutil

package
v1.1.0-beta.0...-8cd7233 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZeroTime = time.Time{}

ZeroTime is a zero time.

Functions

func AreStringSlicesEqual

func AreStringSlicesEqual(a, b []string) bool

AreStringSlicesEqual checks if two string slices are equal. Empyt slice and nil are considered equal. It returns true if the slices are of the same length and all elements are identical in both slices, otherwise, it returns false.

func AreStringSlicesEquivalent

func AreStringSlicesEquivalent(a, b []string) bool

AreStringSlicesEquivalent checks if two string slices are equivalent. If the slices are of the same length and contain the same elements (but possibly in different order), the function returns true.

func BoolToInt

func BoolToInt(b bool) int

BoolToInt converts bool to int.

func BoolToUint64

func BoolToUint64(b bool) uint64

BoolToUint64 converts bool to uint64.

func BytesToUint64

func BytesToUint64(b []byte) (uint64, error)

BytesToUint64 converts a byte slice to uint64.

func DeepClone

func DeepClone[T Codec](src T, factory func() T) T

DeepClone returns the deep copy of the source

func EqualBaseURLs

func EqualBaseURLs(url1, url2 string) bool

EqualBaseURLs compares two URLs without scheme.

func Float64Equal

func Float64Equal(a, b float64) bool

Float64Equal checks if two float64 are equal.

func JSONToUint64Slice

func JSONToUint64Slice(from any) ([]uint64, bool)

JSONToUint64Slice converts JSON slice to uint64 slice.

func MaxUint64

func MaxUint64(a, b uint64) uint64

MaxUint64 returns the max value between two variables whose type are uint64.

func MinDuration

func MinDuration(a, b time.Duration) time.Duration

MinDuration returns the min value between two variables whose type are time.Duration.

func MinUint64

func MinUint64(a, b uint64) uint64

MinUint64 returns the min value between two variables whose type are uint64.

func ParseMBFromText

func ParseMBFromText(text string, value uint64) uint64

ParseMBFromText parses MB from text.

func ParseTimestamp

func ParseTimestamp(data []byte) (time.Time, error)

ParseTimestamp returns a timestamp for a given byte slice.

func SubRealTimeByWallClock

func SubRealTimeByWallClock(after, before time.Time) time.Duration

SubRealTimeByWallClock returns the duration between two different time.Time structs. You should use it to compare the real-world system time. And DO NOT USE IT TO COMPARE two TSOs' physical times directly in some cases.

func SubTSOPhysicalByWallClock

func SubTSOPhysicalByWallClock(after, before time.Time) int64

SubTSOPhysicalByWallClock returns the duration between two different TSOs' physical times with millisecond precision.

func TrimScheme

func TrimScheme(s string) string

TrimScheme trims the scheme from the URL.

func Uint64ToBytes

func Uint64ToBytes(v uint64) []byte

Uint64ToBytes converts uint64 to a byte slice.

Types

type ByteSize

type ByteSize uint64

ByteSize is a retype uint64 for TOML and JSON.

func (ByteSize) MarshalJSON

func (b ByteSize) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*ByteSize) UnmarshalJSON

func (b *ByteSize) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the byte size.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText parses a Toml string into the byte size.

type Codec

type Codec interface {
	Marshal() (data []byte, err error)
	Unmarshal(data []byte) error
}

Codec is the interface representing objects that can marshal and unmarshal themselves.

type Duration

type Duration struct {
	time.Duration
}

Duration is a wrapper of time.Duration for TOML and JSON.

func NewDuration

func NewDuration(duration time.Duration) Duration

NewDuration creates a Duration from time.Duration.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns the duration as a JSON string.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText returns the duration as a JSON string.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the duration.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses a TOML string into the duration.

type StringSlice

type StringSlice []string

StringSlice is more friendly to json encode/decode

func (StringSlice) MarshalJSON

func (s StringSlice) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*StringSlice) UnmarshalJSON

func (s *StringSlice) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the byte size.

Jump to

Keyboard shortcuts

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