Skip to content

Commit

Permalink
Improve nesting in NewID
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmclean committed Aug 18, 2024
1 parent 06540c6 commit a3bb457
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions garden-app/server/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ var (
// NewID creates a new unique xid by default, but mocking can be enabled to choose
// from a consistent list of IDs so results are repeatable
func NewID() babyapi.ID {
if enableMockIDs {
id, err := xid.FromString(ids[mockIDIndex])
if err != nil {
panic(err)
}
mockIDIndex++
if !enableMockIDs {
return babyapi.ID{ID: xid.NewWithTime(clock.Now())}
}

return babyapi.ID{ID: id}
id, err := xid.FromString(ids[mockIDIndex])
if err != nil {
panic(err)
}
return babyapi.ID{ID: xid.NewWithTime(clock.Now())}
mockIDIndex++

return babyapi.ID{ID: id}
}

0 comments on commit a3bb457

Please sign in to comment.