## Description Use of Pointer package in /connector/exchange <!-- Insert PR description--> ## Does this PR need a docs update or release note? Wanted to extend the package to generics, but it is incomplete - [x] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * related #2474<issue> ## Test Plan - [x] ⚡ Unit test
22 lines
603 B
Go
22 lines
603 B
Go
package ptr
|
|
|
|
// ptr package is a common package used for pointer
|
|
// access and deserialization.
|
|
|
|
// Val Generic function for dereferencing pointers.
|
|
// Microsoft Graph saves many variables as string pointers.
|
|
// Function will safely check if the point is nil prior to
|
|
// dereferencing the pointer. If the pointer is nil,
|
|
// an empty version of the object is returned.
|
|
// Operation does not work on Nested objects.
|
|
// For example:
|
|
// *evt.GetEnd().GetDateTime() will still cause a panic
|
|
// if evt is nil or GetEnd() is nil
|
|
func Val[T any](ptr *T) T {
|
|
if ptr == nil {
|
|
return *new(T)
|
|
}
|
|
|
|
return *ptr
|
|
}
|