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

16
utils/ptr/ptr.go Normal file
View File

@@ -0,0 +1,16 @@
package ptr
// Of returns a pointer to v.
func Of[T any](v T) *T { return &v }
// Deref returns the value pointed to by p, or def if p is nil.
func Deref[T any](p *T, def T) T {
if p == nil {
return def
}
return *p
}
// Zero returns the zero value for type T.
func Zero[T any]() (z T) { return }