Documentation
¶
Index ¶
- Constants
- Variables
- func Clone[T any, Slice ~[]T](collection Slice) Slice
- func ContainsCJKChar(s string) bool
- func ConvertUint64ToDecimalString(amount uint64, prec int) string
- func DigitOf[I uint | uint16 | uint32 | uint64 | int | int16 | int32 | int64](val I, n int) I
- func FindDuplicates[T comparable](a []T) []T
- func FromPtrAny[T any](v *any) T
- func FromString[T any](str string) (T, error)
- func FromStringOrEmpty[T any](str string) T
- func Intersection[T comparable](a, b []T) []T
- func IsASCIIPrintable(s string) bool
- func IsDecimalsPlacesValid(num float64, decimalPlaces int) bool
- func IsInTestEnvironment() bool
- func IsJSON(str string) bool
- func IsJSONBytes(bytes []byte) bool
- func IsStringPrintable(str string) bool
- func IsValidUUID(uuidStr string) bool
- func Join[T any](from []T, sep string) string
- func JoinBy[T any](from []T, sep string, convertFunc func(item T) string) string
- func JoinWithConverter[T any](from []T, sep string, convertFunc func(item T) string) stringdeprecated
- func MapString[T any](from []T, sep string) []string
- func MapStringBy[T any](from []T, sep string, convertFunc func(item T) string) []string
- func NormalizeAsRFC1123Name(value string) string
- func ParseUint64FromDecimalString(decimalStr string, percision int) (uint64, error)
- func Print(inputs ...interface{})
- func PrintJSON(inputs ...interface{})
- func Race2[T0 any, T1 any](src1 chan T0, src2 chan T1) (T0, T1)
- func Race3[T0 any, T1 any, T2 any](src1 chan T0, src2 chan T1, src3 chan T2) (T0, T1, T2)
- func Race4[T0 any, T1 any, T2 any, T3 any](src1 chan T0, src2 chan T1, src3 chan T2, src4 chan T3) (T0, T1, T2, T3)
- func Race5[T0 any, T1 any, T2 any, T3 any, T4 any](src1 chan T0, src2 chan T1, src3 chan T2, src4 chan T3, src5 chan T4) (T0, T1, T2, T3, T4)
- func Race6[T0 any, T1 any, T2 any, T3 any, T4 any, T5 any](src1 chan T0, src2 chan T1, src3 chan T2, src4 chan T3, src5 chan T4, ...) (T0, T1, T2, T3, T4, T5)
- func RandBytes(length ...int) ([]byte, error)
- func RandomBase64Token(length ...int) (string, error)
- func RandomHashString(length ...int) string
- func RandomInt64(maxVal ...int64) int64
- func RandomInt64InRange(minVal, maxVal int64) int64
- func RandomInt64String(digits int64) string
- func ReadCSV(path string) ([][]string, error)
- func ReadFileAsBytesBuffer(path string) (*bytes.Buffer, error)
- func RelativePathBasedOnPwdOf(fp string) string
- func RelativePathOf(fp string) string
- func SliceSlices[T any](from []T, each int) [][]T
- func Sprint(inputs ...interface{}) string
- func SprintJSON(inputs ...interface{}) string
- func Stringify(v any) string
- func Substring(str string, start, end int) string
- func Tee[T any](src chan T) (chan T, chan T)
- func ToMap[T any, K comparable](t []T, keyGetter func(T) K) map[K]T
- func ToPtrAny(v any) *any
- type EmptyIoReader
- type EmptyIoWriter
- type NopIoReader
- type NopIoWriter
- type ProtoValueScanner
Constants ¶
const ( UnitBytesOfTB = 1000 * UnitBytesOfGB UnitBytesOfGB = 1000 * UnitBytesOfMB UnitBytesOfMB = 1000 * UnitBytesOfKB UnitBytesOfKB = 1000 UnitBytesOfTiB = 1024 * UnitBytesOfGiB UnitBytesOfGiB = 1024 * UnitBytesOfMiB UnitBytesOfMiB = 1024 * UnitBytesOfKiB UnitBytesOfKiB = 1024 )
Variables ¶
var ( UnitSecondsOfMonth = 30 * UnitSecondsOfDay UnitSecondsOfDay = 24 * UnitSecondsOfHour UnitSecondsOfHour = 60 * UnitSecondsOfMinute UnitSecondsOfMinute = 60 * time.Second )
Functions ¶
func Clone ¶ added in v1.15.1
func Clone[T any, Slice ~[]T](collection Slice) Slice
Clone returns a new slice contains items cloned from collection.
func ContainsCJKChar ¶
ContainsCJKChar determines whether a string contains CJK characters.
func ConvertUint64ToDecimalString ¶
ConvertUint64ToDecimalString formats a uint64 to a string with a decimal point.
func DigitOf ¶
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 FromPtrAny ¶ added in v1.9.7
FromPtrAny returns the value from the given pointer.
func FromString ¶ added in v1.9.7
func FromStringOrEmpty ¶ added in v1.9.7
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 ¶
IsASCIIPrintable determines whether a string is printable ASCII.
func IsDecimalsPlacesValid ¶
func IsInTestEnvironment ¶
func IsInTestEnvironment() bool
IsInTestEnvironment determines whether the current environment is a test environment.
func IsJSONBytes ¶
IsJSONBytes determines whether the bytes is JSON.
func IsStringPrintable ¶
IsStringPrintable determines whether a string is printable.
func IsValidUUID ¶
IsValidUUID determines whether a string is a valid UUID.
func JoinWithConverter
deprecated
func MapStringBy ¶ added in v1.9.7
MapStringBy returns a new slice contains converted items.
func NormalizeAsRFC1123Name ¶ added in v1.9.7
func ParseUint64FromDecimalString ¶
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 RandomBase64Token ¶
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 ¶
RandomHashString generates a random SHA256 string with the maximum length of 64.
func RandomInt64InRange ¶
RandomInt64InRange generates a random integer in the range.
func RandomInt64String ¶
RandomInt64String generates a random integer string.
func ReadFileAsBytesBuffer ¶
ReadFileAsBytesBuffer reads a file and returns a bytes.Buffer.
func RelativePathOf ¶
func SliceSlices ¶
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
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
type ProtoValueScanner ¶ added in v1.9.7
type ProtoValueScanner[T any] struct { }
ProtoValueScanner is a field.ValueScanner that implements the ent.ValueScanner interface as helper for working with protobuf messages. It is used to scan and convert protobuf messages to and from the database.
func (SomeTable) Fields() []ent.Field {
return []ent.Field{
field.
String("payload").
ValueScanner(utils.ProtoValueScanner[somepb.YourMessage]{}).
GoType(&somepb.YourMessage{}).
SchemaType(map[string]string{
dialect.Postgres: "jsonb",
dialect.MySQL: "json",
dialect.SQLite: "json",
}),
}
}
func (ProtoValueScanner[T]) FromValue ¶ added in v1.9.7
func (s ProtoValueScanner[T]) FromValue(value driver.Value) (vt *T, err error)
FromValue returns the field instance from the ScanValue above after the database value was scanned.
func (ProtoValueScanner[T]) ScanValue ¶ added in v1.9.7
func (s ProtoValueScanner[T]) ScanValue() field.ValueScanner
ScanValue returns a new ValueScanner that functions as an intermediate result between database value and GoType value. For example, sql.NullString or sql.NullInt.