2022-02-22 09:35:44 +01:00
|
|
|
package managers
|
2022-02-20 11:55:11 +01:00
|
|
|
|
2022-03-08 12:01:51 +01:00
|
|
|
import (
|
2022-03-12 15:57:27 +01:00
|
|
|
"StoreBackEnd/pkg/protocol"
|
2022-03-08 12:01:51 +01:00
|
|
|
"StoreBackEnd/pkg/protocol/repository"
|
2022-03-08 20:37:49 +01:00
|
|
|
"bufio"
|
2022-03-08 12:01:51 +01:00
|
|
|
)
|
2022-02-20 12:35:05 +01:00
|
|
|
|
2022-02-20 11:55:11 +01:00
|
|
|
type RequestManager struct {
|
2022-02-22 08:29:11 +01:00
|
|
|
Repository *repository.ProtocolRepository
|
2022-02-20 11:55:11 +01:00
|
|
|
}
|
|
|
|
|
2022-03-12 15:57:27 +01:00
|
|
|
func (receiver RequestManager) Execute(request string, reader *bufio.Reader) *protocol.ProtocolWriterResult {
|
2022-02-20 11:55:11 +01:00
|
|
|
// On lis ce que l'on reçoit
|
2022-03-12 15:57:27 +01:00
|
|
|
writeCmd, readCb := receiver.Repository.ExecuteReader(request)
|
2022-03-08 17:44:10 +01:00
|
|
|
|
2022-02-20 11:55:11 +01:00
|
|
|
// On renvoie la réponse (Comment pour fichier ?)
|
2022-03-12 15:57:27 +01:00
|
|
|
if writeCmd != nil {
|
2022-03-08 12:01:51 +01:00
|
|
|
if readCb != nil {
|
2022-03-12 15:57:27 +01:00
|
|
|
cbResult := readCb(reader)
|
|
|
|
if cbResult != nil {
|
|
|
|
writeCmd = cbResult
|
2022-03-08 12:01:51 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-12 15:57:27 +01:00
|
|
|
return writeCmd
|
2022-02-20 12:35:05 +01:00
|
|
|
} else {
|
2022-03-12 15:57:27 +01:00
|
|
|
return nil
|
2022-02-20 12:35:05 +01:00
|
|
|
}
|
2022-02-20 11:55:11 +01:00
|
|
|
}
|