-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image comparison: use source url #129
base: entities
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package yext | |
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
) | ||
|
||
const ENTITYTYPE_LOCATION EntityType = "location" | ||
|
@@ -208,6 +209,7 @@ type Photo struct { | |
type Image struct { | ||
Url *string `json:"url,omitempty"` | ||
AlternateText *string `json:"alternateText,omitempty"` | ||
SourceUrl *string `json:"sourceUrl,omitempty"` | ||
} | ||
|
||
func NullableImage(i *Image) **Image { | ||
|
@@ -226,6 +228,26 @@ func NullImage() **Image { | |
return &i | ||
} | ||
|
||
// If source URL is filled in, Image came from Yext API and source URL should be | ||
// used for comparison as URL is the mktg cdn generated URL | ||
func (a *Image) Equal(b Comparable) bool { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
log.Printf("Value of A: %+v, Value of B:%+v, Type Of A: %T, Type Of B: %T\n", a, b, a, b) | ||
panic(r) | ||
} | ||
}() | ||
|
||
if a.SourceUrl != nil { | ||
a.Url = a.SourceUrl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mutating the source seems wacky - can we compare the source URL directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure but i wanted to make sure it was only the source url and url that is different, i don't have a great way of doing that other than porting reflection here (the diff) or writing code to compare attribute to attribute, which if we add an attribute we'd have to remember to update this code too, so that seems dangerous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm uncomfortable with the idea of the equal function modifying the receiver that it's called on? could we copy it instead and then call genericdiff on the copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure! |
||
a.SourceUrl = nil | ||
_, isDiff := GenericDiff(a, b, false, false) | ||
return !isDiff | ||
} | ||
_, isDiff := GenericDiff(a, b, false, false) | ||
return !isDiff | ||
} | ||
|
||
type Address struct { | ||
Line1 *string `json:"line1,omitempty"` | ||
Line2 *string `json:"line2,omitempty"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mean to leave this in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it follows the model of the other Equal implementations in yext-go