Skip to content
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

Add Server-Sent Events example #209

Merged
merged 32 commits into from
Nov 17, 2020
Merged

Add Server-Sent Events example #209

merged 32 commits into from
Nov 17, 2020

Conversation

m110
Copy link
Member

@m110 m110 commented Nov 14, 2020

No description provided.


filter := bson.M{
"_id": bson.M{
"$in": post.Tags,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are post.Tags a slice of mongo _ids? or is the _id field not a mongo _id, but any string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feed's name is used as _id, and tags are feed names. It's just a string, I didn't bother with Mongo's ObjectId for simplicity's sake.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be confusing tho, for people expecting _id to be a ObjectID
but if it would add a lot of complication to separate those, then let's leave it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mongo doesn't specify it has to be ObjectId, though. _id is just a unique primary key and indexed by default, which makes sense for the feed name.


func (s FeedsStorage) ByName(ctx context.Context, name string) (Feed, error) {
filter := bson.M{
"_id": name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here, with the _id an ObjectID.
may be confusing, but up to you

return false
}

return mErr.WriteErrors[0].Code == 11000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a const for that? 🧙

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not. 😢


tagsCount := rand.Intn(3) + 1
for i := 0; i < tagsCount; i++ {
content += fmt.Sprintf(" #%v", generatedTags[rand.Intn(len(generatedTags))])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use gofakeit.RandomString for that, since the example uses gofakeit already.
however, s[rand.Intn(len(s))] is kinda idiomatic in Golang now, so it might be even more readable 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use a static list for these tags, as RandomString would produce a new string every time. In the current approach, you can see the posts in feed number increase as you click the button.

@m110 m110 merged commit 2e1819e into master Nov 17, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants