-
Notifications
You must be signed in to change notification settings - Fork 388
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
Conversation
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Outdated
Show resolved
Hide resolved
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Show resolved
Hide resolved
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Outdated
Show resolved
Hide resolved
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Outdated
Show resolved
Hide resolved
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Show resolved
Hide resolved
|
||
filter := bson.M{ | ||
"_id": bson.M{ | ||
"$in": post.Tags, |
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.
are post.Tags
a slice of mongo _id
s? or is the _id
field not a mongo _id
, but any string?
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.
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.
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.
fair enough
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.
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
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.
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.
_examples/real-world-examples/server-sent-events/server/event_handlers.go
Show resolved
Hide resolved
|
||
func (s FeedsStorage) ByName(ctx context.Context, name string) (Feed, error) { | ||
filter := bson.M{ | ||
"_id": name, |
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.
same thing here, with the _id
an ObjectID
.
may be confusing, but up to you
return false | ||
} | ||
|
||
return mErr.WriteErrors[0].Code == 11000 |
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.
is there a const for that? 🧙
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.
There's not. 😢
|
||
tagsCount := rand.Intn(3) + 1 | ||
for i := 0; i < tagsCount; i++ { | ||
content += fmt.Sprintf(" #%v", generatedTags[rand.Intn(len(generatedTags))]) |
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.
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 😁
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.
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.
No description provided.