move isNil func to common/prt
This commit is contained in:
parent
e739ef5d4f
commit
3d8f9e40ab
@ -1,6 +1,9 @@
|
|||||||
package ptr
|
package ptr
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// ptr package is a common package used for pointer
|
// ptr package is a common package used for pointer
|
||||||
// access and deserialization.
|
// access and deserialization.
|
||||||
@ -50,3 +53,17 @@ func OrNow(t *time.Time) time.Time {
|
|||||||
func To[T any](t T) *T {
|
func To[T any](t T) *T {
|
||||||
return &t
|
return &t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNil check if type provided is nil
|
||||||
|
func IsNil(i any) bool {
|
||||||
|
if i == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch reflect.TypeOf(i).Kind() {
|
||||||
|
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
|
||||||
|
return reflect.ValueOf(i).IsNil()
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@ -211,7 +211,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
|
|||||||
return ptr.Val(folder.GetId())
|
return ptr.Val(folder.GetId())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
//TODO: Neha complete as part of https://github.com/alcionai/corso/issues/2428
|
// TODO: Neha complete as part of https://github.com/alcionai/corso/issues/2428
|
||||||
// {
|
// {
|
||||||
// name: "Test Mail: Hydrated Item Attachment Mail",
|
// name: "Test Mail: Hydrated Item Attachment Mail",
|
||||||
// bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
|
// bytes: exchMock.MessageWithNestedItemAttachmentMail(t,
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package exchange
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -259,7 +258,7 @@ func sanitizeEvent(orig models.Eventable) (models.Eventable, error) {
|
|||||||
newEvent.SetIsAllDay(orig.GetIsAllDay())
|
newEvent.SetIsAllDay(orig.GetIsAllDay())
|
||||||
newEvent.SetIsOnlineMeeting(orig.GetIsOnlineMeeting())
|
newEvent.SetIsOnlineMeeting(orig.GetIsOnlineMeeting())
|
||||||
|
|
||||||
if !isNil(orig.GetLocation()) {
|
if !ptr.IsNil(orig.GetLocation()) {
|
||||||
newEvent.SetLocation(orig.GetLocation())
|
newEvent.SetLocation(orig.GetLocation())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,19 +289,6 @@ func sanitizeEvent(orig models.Eventable) (models.Eventable, error) {
|
|||||||
return newEvent, nil
|
return newEvent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func isNil(i interface{}) bool {
|
|
||||||
if i == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
switch reflect.TypeOf(i).Kind() {
|
|
||||||
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
|
|
||||||
return reflect.ValueOf(i).IsNil()
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func sanitizeMessage(orig models.Messageable) (models.Messageable, error) {
|
func sanitizeMessage(orig models.Messageable) (models.Messageable, error) {
|
||||||
message := toMessage(orig)
|
message := toMessage(orig)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user