Documentation ΒΆ
Index ΒΆ
- Constants
- Variables
- 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 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 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 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.