feat: add utility functions for environment variable handling, file operations, pointer manipulation, random generation, and string processing
This commit is contained in:
16
utils/ptr/ptr.go
Normal file
16
utils/ptr/ptr.go
Normal 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 }
|
||||
|
||||
Reference in New Issue
Block a user