lang(Go language extensions)

Utility functions and extensions for common Go programming tasks, organized into several sub-packages.

The lang module provides utility functions and extensions for common Go programming tasks, organized into several sub-packages.

Sub-packages

  • conv: Type conversion utilities
  • ptr: Pointer manipulation helpers
  • maps: Map operation utilities
  • sets: Set data structure operations
  • slices: Slice manipulation functions
  • crypto: Cryptographic utilities

conv - Type Conversion

 1package main
 2
 3import (
 4    "fmt"
 5	
 6    "github.com/crazyfrankie/frx/lang/conv"
 7)
 8
 9func main() {
10    // String to int64 conversion
11    num, err := conv.StrToInt64("12345")
12    if err != nil {
13        panic(err)
14    }
15    fmt.Printf("Converted number: %d\n", num)
16    
17    // String to int64 with default value
18    numWithDefault := conv.StrToInt64D("invalid", 0)
19    fmt.Printf("Number with default: %d\n", numWithDefault)
20    
21    // Int64 to string
22    str := conv.Int64ToStr(12345)
23    fmt.Printf("Converted string: %s\n", str)
24    
25    // Debug JSON conversion
26    data := map[string]interface{}{
27        "name": "John",
28        "age":  30,
29    }
30    jsonStr := conv.DebugJsonToStr(data)
31    fmt.Printf("JSON string: %s\n", jsonStr)
32    
33    // Bool to int conversion
34    intVal := conv.BoolToInt(true)  // returns 1
35    fmt.Printf("Bool to int: %d\n", intVal)
36}

ptr - Pointer Utilities

 1package main
 2
 3import (
 4    "fmt"
 5	
 6    "github.com/crazyfrankie/frx/lang/ptr"
 7)
 8
 9func main() {
10    // Create pointer from value
11    value := 42
12    valuePtr := ptr.Of(value)
13    fmt.Printf("Pointer value: %d\n", *valuePtr)
14    
15    // Get value from pointer
16    retrievedValue := ptr.From(valuePtr)
17    fmt.Printf("Retrieved value: %d\n", retrievedValue)
18    
19    // Get value from pointer with default
20    var nilPtr *int
21    defaultValue := ptr.FromOrDefault(nilPtr, 100)
22    fmt.Printf("Default value: %d\n", defaultValue)
23}