Messaging service, adapters, refactoring
This commit is contained in:
32
adapters/randomstring/service.go
Normal file
32
adapters/randomstring/service.go
Normal 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)
|
||||
}
|
||||
25
adapters/stdoutstore/service.go
Normal file
25
adapters/stdoutstore/service.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package stdoutstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func New() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
}
|
||||
|
||||
func (s *Service) StoreReceived(_ context.Context, sender, message string) error {
|
||||
fmt.Printf("Received '%s' from <%s>\n", message, sender)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) StoreSent(_ context.Context, sender, message string) error {
|
||||
fmt.Printf("Sent '%s' to <%s>\n", message, sender)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user