Refactoring Tracer and ProtocolManager

This commit is contained in:
Mario
2022-06-04 17:14:46 +02:00
parent 1aafe73505
commit ab5a4f8137
3 changed files with 11 additions and 7 deletions

View File

@ -58,7 +58,7 @@ type ReadFileBytesByFilePath func(filePath string) ([]byte, error)
type GelAllFilesNameByDirName func(dirName string) ([]string, error)
// Init Parser, return a configurationsParser and use the DI Pattern to inject the dependencies
// Init Parser, return a configurationsParser and use the D.I. Pattern to inject the dependencies
func Init(configurationsCorePath, configurationsServicesDirectory string) *configurationsParser {
return &configurationsParser{
configurationsCorePath: configurationsCorePath,

View File

@ -11,7 +11,7 @@ type ServiceStrategy interface {
type ProtocolManager struct {
strategy ServiceStrategy
tracer *tracer.Tracer
tracer tracer.Tracer
}
func InitProtocolManager(tracerStrategy tracer.Strategy, strategy ServiceStrategy) *ProtocolManager {
@ -26,5 +26,5 @@ func (pm *ProtocolManager) SetProtocolStrategy(strategy ServiceStrategy) {
}
func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error {
return pm.strategy.Init(beelzebubServiceConfiguration, *pm.tracer)
return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer)
}

View File

@ -6,17 +6,21 @@ import (
type Strategy func(event Event)
type Tracer struct {
type Tracer interface {
TraceEvent(event Event)
}
type tracer struct {
strategy Strategy
}
func Init(strategy Strategy) *Tracer {
return &Tracer{
func Init(strategy Strategy) *tracer {
return &tracer{
strategy: strategy,
}
}
func (tracer *Tracer) TraceEvent(event Event) {
func (tracer *tracer) TraceEvent(event Event) {
event.DateTime = time.Now().UTC().Format(time.RFC3339)
tracer.strategy(event)
}