mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Refactoring Tracer and ProtocolManager
This commit is contained in:
@ -58,7 +58,7 @@ type ReadFileBytesByFilePath func(filePath string) ([]byte, error)
|
|||||||
|
|
||||||
type GelAllFilesNameByDirName func(dirName string) ([]string, 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 {
|
func Init(configurationsCorePath, configurationsServicesDirectory string) *configurationsParser {
|
||||||
return &configurationsParser{
|
return &configurationsParser{
|
||||||
configurationsCorePath: configurationsCorePath,
|
configurationsCorePath: configurationsCorePath,
|
||||||
|
@ -11,7 +11,7 @@ type ServiceStrategy interface {
|
|||||||
|
|
||||||
type ProtocolManager struct {
|
type ProtocolManager struct {
|
||||||
strategy ServiceStrategy
|
strategy ServiceStrategy
|
||||||
tracer *tracer.Tracer
|
tracer tracer.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitProtocolManager(tracerStrategy tracer.Strategy, strategy ServiceStrategy) *ProtocolManager {
|
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 {
|
func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error {
|
||||||
return pm.strategy.Init(beelzebubServiceConfiguration, *pm.tracer)
|
return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer)
|
||||||
}
|
}
|
||||||
|
@ -6,17 +6,21 @@ import (
|
|||||||
|
|
||||||
type Strategy func(event Event)
|
type Strategy func(event Event)
|
||||||
|
|
||||||
type Tracer struct {
|
type Tracer interface {
|
||||||
|
TraceEvent(event Event)
|
||||||
|
}
|
||||||
|
|
||||||
|
type tracer struct {
|
||||||
strategy Strategy
|
strategy Strategy
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(strategy Strategy) *Tracer {
|
func Init(strategy Strategy) *tracer {
|
||||||
return &Tracer{
|
return &tracer{
|
||||||
strategy: strategy,
|
strategy: strategy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tracer *Tracer) TraceEvent(event Event) {
|
func (tracer *tracer) TraceEvent(event Event) {
|
||||||
event.DateTime = time.Now().UTC().Format(time.RFC3339)
|
event.DateTime = time.Now().UTC().Format(time.RFC3339)
|
||||||
tracer.strategy(event)
|
tracer.strategy(event)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user