fix: refactor code to be testable #181
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 55s
Build Docker Image / Build-Docker-Image (push) Successful in 45s

This commit was merged in pull request #212.
This commit is contained in:
2024-10-12 21:57:39 +02:00
parent 9fd9f9649e
commit 1ed504c49b
19 changed files with 1022 additions and 710 deletions

View File

@@ -10,20 +10,20 @@ import (
"github.com/google/uuid"
)
type RandomGenerator interface {
type RandomService interface {
Bytes(size int) ([]byte, error)
String(size int) (string, error)
UUID() (uuid.UUID, error)
}
type RandomGeneratorImpl struct {
type RandomServiceImpl struct {
}
func NewRandomGeneratorImpl() *RandomGeneratorImpl {
return &RandomGeneratorImpl{}
func NewRandomServiceImpl() *RandomServiceImpl {
return &RandomServiceImpl{}
}
func (r *RandomGeneratorImpl) Bytes(size int) ([]byte, error) {
func (r *RandomServiceImpl) Bytes(size int) ([]byte, error) {
b := make([]byte, 32)
_, err := rand.Read(b)
if err != nil {
@@ -34,7 +34,7 @@ func (r *RandomGeneratorImpl) Bytes(size int) ([]byte, error) {
return b, nil
}
func (r *RandomGeneratorImpl) String(size int) (string, error) {
func (r *RandomServiceImpl) String(size int) (string, error) {
bytes, err := r.Bytes(size)
if err != nil {
return "", types.ErrInternal
@@ -43,6 +43,6 @@ func (r *RandomGeneratorImpl) String(size int) (string, error) {
return base64.StdEncoding.EncodeToString(bytes), nil
}
func (r *RandomGeneratorImpl) UUID() (uuid.UUID, error) {
func (r *RandomServiceImpl) UUID() (uuid.UUID, error) {
return uuid.NewRandom()
}