-
Notifications
You must be signed in to change notification settings - Fork 164
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
Lab6 - Puppy Storer - alfredxiao #476
Conversation
Codecov Report
@@ Coverage Diff @@
## master #476 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 107 110 +3
Lines 1861 1923 +62
=====================================
+ Hits 1861 1923 +62
Continue to review full report at Codecov.
|
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.
Looks really good, nothing i can see that would make me not approve.
06_puppy/alfredxiao/store_test.go
Outdated
t := s.T() | ||
_ = s.store.CreatePuppy(Puppy{ID: "3", Colour: "Blue"}) | ||
p, err := s.store.ReadPuppy("3") | ||
require.NoError(t, err) |
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.
Why the mix of require and assert?
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.
require is for not continuing with other assertions when it fails, assertions do not have this attribute. In this case, my thought was that if err
is Error
then there is no point in continuing.
"sync" | ||
) | ||
|
||
type syncStore struct { |
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.
Interesting choice to make this private.
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.
Don't make it private :)
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.
Gotta run now, but rushed, but should give you a start :)
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.
- Limit the number of commits to one or two
- Fix commit messages - Capitalise first word in commit message.
If you need help with this, please reach out and/or come over.
You'll also have to add a mutex to add agains race condition in the syncmap implementation (the point of using sync.Map is to protect your code from race conditions - make it "thread/goroutine safe").
Other than that looks pretty solid, well done.
data map[string]Puppy | ||
} | ||
|
||
func (s *mapStore) CreatePuppy(p Puppy) 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.
Use godoc for all public functions.
} | ||
|
||
func (s *mapStore) UpdatePuppy(id string, p Puppy) error { | ||
if id != p.ID { |
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.
not sure why you'd have separate id field?
} | ||
|
||
_, ok := s.data[id] | ||
if !ok { |
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.
if _, ok := s.data[id]; !ok {
same below.
"sync" | ||
) | ||
|
||
type syncStore struct { |
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.
Don't make it private :)
} | ||
|
||
func (s *syncStore) CreatePuppy(p Puppy) string { | ||
id := uuid.New().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.
👍
return fmt.Errorf("puppy with ID[%s] does not exists", p.ID) | ||
} | ||
|
||
s.data.Store(id, p) |
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.
Fixes #475
Review of colleague's PR #436
Changes proposed in this PR:
Storer
using mapStorer
using sync.map