Documentation
¶
Overview ¶
Package utils provides utility functions for converting types to strings and integers.
Index ¶
- Variables
- func BoolToByte(b bool) byte
- func ByteToBool(b byte) bool
- func CurrentTimeStr() string
- func GetDateRange(value string) (fromDate, toDate string)
- func IfThen[T any](condition bool, a T) (b T)
- func IfThenElse[T any](condition bool, a T, b T) T
- func IsValidEmail(email string) bool
- func Pluck[T any, K any](subject *[]T, key string, destination *[]K)
- func Ptr[T any](value T) *T
- func Round(val float64, precision int) float64
- func SliceToMap[T any](slice []T) []map[string]any
- func StringClean(str string, limit int) string
- func StringContainsIgnoreCase(str, substr string) bool
- func StringSliceMergeUnique(original, slice *[]string) []string
- func ToInt[...](value T) int
- func ToJsonMap[T any](item T) map[string]any
- func ToMap[T any](item T) map[string]any
- func ToString[T any](value T) string
- func WithDefault[T int | string](value T, defaultValue T) T
- type Pipeline
- type PipelineContext
- type PipelineStep
Constants ¶
This section is empty.
Variables ¶
var ValidEmailRegexp = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
ValidEmailRegexp is the standard email validation pattern.
Functions ¶
func ByteToBool ¶
func CurrentTimeStr ¶
func CurrentTimeStr() string
CurrentTimeStr returns the current time formatted as "YYYY-MM-DD HH:MM:SS".
func GetDateRange ¶
GetDateRange returns the date range based on the given value keyword. Supported: "today", "yesterday", "this_week", "last_week", "this_month", "last_month", "this_year", "last_year".
func IfThen ¶
IfThen returns 'a' if condition is true, otherwise the zero value of T. Note: This is less safe than IfThenElse because the zero value might be meaningful.
func IfThenElse ¶
IfThenElse returns 'a' if condition is true, otherwise 'b'.
func IsValidEmail ¶
func SliceToMap ¶
SliceToMap converts a slice of structs to a slice of maps.
func StringClean ¶
StringClean truncates a string to a given rune-count limit and trims whitespace. Truncation is performed at rune (Unicode code point) boundaries to avoid producing invalid UTF-8.
func StringSliceMergeUnique ¶
--- Slice Helpers ---
func ToInt ¶
func ToInt[T int | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | float32 | float64 | string](value T) int
ToInt converts various types to int.
func WithDefault ¶
WithDefault returns defaultValue if value is the zero value for its type (0 or ""). Currently supports int and string.
Types ¶
type Pipeline ¶
type Pipeline[T any] struct { // contains filtered or unexported fields }
func NewPipeline ¶
func (*Pipeline[T]) AddStep ¶
func (p *Pipeline[T]) AddStep(step PipelineStep[T]) *Pipeline[T]
func (*Pipeline[T]) GetSubject ¶
func (p *Pipeline[T]) GetSubject() *T
func (*Pipeline[T]) WithContext ¶
func (p *Pipeline[T]) WithContext(ctx *PipelineContext) *Pipeline[T]
type PipelineContext ¶
type PipelineContext struct {
// contains filtered or unexported fields
}
func NewPipelineContext ¶
func NewPipelineContext() *PipelineContext
func (*PipelineContext) Set ¶
func (pc *PipelineContext) Set(key string, value any)
type PipelineStep ¶
type PipelineStep[T any] func(*T, *PipelineContext) error