feat: add utility functions for environment variable handling, file operations, pointer manipulation, random generation, and string processing

This commit is contained in:
Rogee
2025-09-12 11:40:52 +08:00
parent 205c08b00d
commit 744ae45c15
6 changed files with 491 additions and 0 deletions

28
utils/jsonx/json.go Normal file
View File

@@ -0,0 +1,28 @@
package jsonx
import "encoding/json"
func Marshal(v any) ([]byte, error) {
return json.Marshal(v)
}
func Unmarshal[T any](data []byte) (*T, error) {
var v T
err := json.Unmarshal(data, &v)
if err != nil {
return nil, err
}
return &v, nil
}
func UnmarshalTo(data []byte, a any) error {
return json.Unmarshal(data, a)
}
func MustUnmarshal[T any](data []byte) *T {
v, err := Unmarshal[T](data)
if err != nil {
panic(err)
}
return v
}