-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.go
More file actions
24 lines (20 loc) · 601 Bytes
/
utils.go
File metadata and controls
24 lines (20 loc) · 601 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package hot
import "reflect"
// emptyableToPtr returns a pointer copy of value if it's nonzero.
// Otherwise, returns nil pointer.
func emptyableToPtr[T any](x T) *T {
// Use reflection to check if the value is zero. This is necessary because
// the zero value of generic types cannot be determined directly.
isZero := reflect.ValueOf(&x).Elem().IsZero()
if isZero {
return nil
}
return &x
}
// assertValue panics with the given message if the condition is false.
// This is used for validating configuration parameters.
func assertValue(ok bool, msg string) {
if !ok {
panic(msg)
}
}