Skip to content

Commit

Permalink
feat(convert): refactor codebase for improved performance and maintai…
Browse files Browse the repository at this point in the history
…nability

- Add `ToPtr` function to convert a value to a pointer in a generic way

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Oct 25, 2024
1 parent b7159ec commit ab0df18
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ func ToFloat(value interface{}) interface{} {
}
return 0.0
}

// ToPtr takes a value of any type and returns a pointer to that value.
// This is useful for converting a value to a pointer in a generic way.
//
// T: The type of the value being converted.
// value: The value to be converted to a pointer.
//
// Returns a pointer to the provided value.
func ToPtr[T any](value T) *T {
return &value
}

0 comments on commit ab0df18

Please sign in to comment.