Messaging service, adapters, refactoring

This commit is contained in:
2023-12-07 09:00:30 +03:00
parent cf00cfaab6
commit 08a7c9c04f
18 changed files with 623 additions and 53 deletions

View File

@@ -0,0 +1,32 @@
package randomstring
import (
"context"
"math/rand"
)
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
type Service struct {
chars []rune
length int
size uint
}
func New(size uint) *Service {
return &Service{
chars: []rune(chars),
length: len([]rune(chars)),
size: size,
}
}
func (s *Service) NewString(context.Context) string {
res := make([]rune, s.size)
for i := uint(0); i < s.size; i++ {
res[i] = s.chars[rand.Intn(s.length)]
}
return string(res)
}