package utils import ( "os" "strconv" "strings" ) var MARKDOWN_ESC []string = []string{"_", "*", "[", "]", "(", ")", "~", "`", ">", "#", "+", "-", "=", "|", "{", "}", ".", "!"} func WriteMDv2Text( sb *strings.Builder, t string ) { for _, c := range MARKDOWN_ESC { t = strings.Replace( t, c, "\\" + c, -1 ) } sb.WriteString( t ) } func ToPower( t string ) string { for s, r := range POWER_NUMBERS { t = strings.ReplaceAll( t, s, r ) } return t } func TryGetEnv[T any]( name string, fallback T ) T { v := os.Getenv( name ) if v != "" { switch any( fallback ).(type) { case uint64: p, err := strconv.ParseUint( v, 10, 64 ) if err == nil { return any( uint64( p ) ).(T) } case uint32: p, err := strconv.ParseUint( v, 10, 32 ) if err == nil { return any( uint32( p ) ).(T) } case int: p, err := strconv.ParseInt( v, 10, 32 ) if err == nil { return any( int( p ) ).(T) } case float64: p, err := strconv.ParseFloat( v, 64 ) if err == nil { return any( float64( p ) ).(T) } case float32: p, err := strconv.ParseFloat( v, 32 ) if err == nil { return any( float32( p ) ).(T) } default: return any( v ).(T) } } return fallback }