-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from segmentio/jeremy/remove-internal-message
Remove message internal-only restriction and add ValidateFields
- Loading branch information
Showing
11 changed files
with
416 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package analytics | ||
|
||
type FieldGetter interface { | ||
GetField(field string) (interface{}, bool) | ||
} | ||
|
||
func getString(msg FieldGetter, field string) string { | ||
if val, ok := msg.GetField(field); ok { | ||
if str, ok := val.(string); ok { | ||
return str | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
func ValidateFields(msg FieldGetter) error { | ||
typ, _ := msg.GetField("type") | ||
if str, ok := typ.(string); ok { | ||
switch str { | ||
case "alias": | ||
return Alias{ | ||
Type: "alias", | ||
UserId: getString(msg, "userId"), | ||
PreviousId: getString(msg, "previousId"), | ||
}.Validate() | ||
case "group": | ||
return Group{ | ||
Type: "group", | ||
UserId: getString(msg, "userId"), | ||
AnonymousId: getString(msg, "anonymousId"), | ||
GroupId: getString(msg, "groupId"), | ||
}.Validate() | ||
case "identify": | ||
return Identify{ | ||
Type: "identify", | ||
UserId: getString(msg, "userId"), | ||
AnonymousId: getString(msg, "anonymousId"), | ||
}.Validate() | ||
case "page": | ||
return Page{ | ||
Type: "page", | ||
UserId: getString(msg, "userId"), | ||
AnonymousId: getString(msg, "anonymousId"), | ||
}.Validate() | ||
case "screen": | ||
return Screen{ | ||
Type: "screen", | ||
UserId: getString(msg, "userId"), | ||
AnonymousId: getString(msg, "anonymousId"), | ||
}.Validate() | ||
case "track": | ||
return Track{ | ||
Type: "track", | ||
UserId: getString(msg, "userId"), | ||
AnonymousId: getString(msg, "anonymousId"), | ||
Event: getString(msg, "event"), | ||
}.Validate() | ||
} | ||
} | ||
return FieldError{ | ||
Type: "analytics.Event", | ||
Name: "Type", | ||
Value: typ, | ||
} | ||
} |
Oops, something went wrong.