-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle case when a new booking triggers a conflict with another exist…
…ing booking
- Loading branch information
1 parent
a16d799
commit d5d814e
Showing
7 changed files
with
146 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package chaos | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/binary" | ||
"math/rand" | ||
) | ||
|
||
func stringToSeed(s string) uint64 { | ||
hash := sha256.Sum256([]byte(s)) | ||
return binary.BigEndian.Uint64(hash[:8]) | ||
} | ||
|
||
func Int(seed string, cap int) int { | ||
if cap == 0 { | ||
return 0 | ||
} | ||
u := stringToSeed(seed) | ||
r := rand.New(rand.NewSource(int64(u))) | ||
return r.Int() % cap | ||
} |
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,25 @@ | ||
package id | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/google/uuid" | ||
"github.com/raphoester/space-trouble-api/internal/pkg/chaos" | ||
) | ||
|
||
type ChaoticGenerator struct { | ||
rnd *rand.Rand | ||
} | ||
|
||
func NewChaoticFactory(seed string) *ChaoticGenerator { | ||
rnd := rand.New(rand.NewSource(int64(chaos.Int(seed, 100)))) | ||
return &ChaoticGenerator{rnd: rnd} | ||
} | ||
|
||
func (g *ChaoticGenerator) Generate() ID { | ||
id, err := uuid.NewRandomFromReader(g.rnd) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ID(id.String()) | ||
} |