-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: ⚡ implements specific setup methods for localhost and remote host
Signed-off-by: Lucas Vieira <lucas.engen.cc@gmail.com>
- Loading branch information
Showing
1 changed file
with
70 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,70 @@ | ||
package telemetry | ||
|
||
import ( | ||
"github.com/lucasvmx/WarTelemetry/controller" | ||
"github.com/lucasvmx/WarTelemetry/logger" | ||
"github.com/lucasvmx/WarTelemetry/model" | ||
"github.com/lucasvmx/WarTelemetry/utils" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
var errGroup *errgroup.Group | ||
|
||
var ( | ||
collectors = map[string]func() error{ | ||
"gamechat": controller.GetGamechatData, | ||
"indicators": controller.GetIndicatorsData, | ||
"map_info": controller.GetMapInfoData, | ||
"hud_msg": controller.GetHudMessagesData, | ||
"map_obj": controller.GetMapObjsData, | ||
"state": controller.GetStateData, | ||
"mission": controller.GetMissionData, | ||
} | ||
) | ||
|
||
// Initialize function setup the library to be used | ||
func Initialize(hostname string) { | ||
if len(hostname) > 0 { | ||
utils.SetHostname(hostname) | ||
} else { | ||
logger.LogInfo("Hostname omitted. Using localhost") | ||
} | ||
|
||
model.SetupTelemetry() | ||
errGroup = new(errgroup.Group) | ||
} | ||
|
||
func getTelemetryData() error { | ||
|
||
for name, callback := range collectors { | ||
logger.LogInfo("running task to get %v data", name) | ||
errGroup.Go(callback) | ||
} | ||
|
||
return errGroup.Wait() | ||
} | ||
|
||
// GetTelemetryData function retrieves all telemetry data | ||
func GetTelemetryData() (data *model.TelemetryData, err error) { | ||
|
||
// Initialize struct | ||
data = &model.TelemetryData{} | ||
|
||
if fail := getTelemetryData(); fail != nil { | ||
return nil, fail | ||
} | ||
|
||
data.MapInfo = model.GetInstance().MapInfo | ||
data.Gamechat = model.GetInstance().Gamechat | ||
data.Indicators = model.GetInstance().Indicators | ||
data.State = model.GetInstance().State | ||
data.HudMessages = model.GetInstance().HudMessages | ||
data.MapObjects = model.GetInstance().MapObjects | ||
data.MissionInfo = model.GetInstance().MissionInfo | ||
|
||
return | ||
} | ||
package telemetry | ||
|
||
import ( | ||
"github.com/lucasvmx/WarTelemetry/controller" | ||
"github.com/lucasvmx/WarTelemetry/logger" | ||
"github.com/lucasvmx/WarTelemetry/model" | ||
"github.com/lucasvmx/WarTelemetry/utils" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
var errGroup *errgroup.Group | ||
|
||
var ( | ||
collectors = map[string]func() error{ | ||
"gamechat": controller.GetGamechatData, | ||
"indicators": controller.GetIndicatorsData, | ||
"map_info": controller.GetMapInfoData, | ||
"hud_msg": controller.GetHudMessagesData, | ||
"map_obj": controller.GetMapObjsData, | ||
"state": controller.GetStateData, | ||
"mission": controller.GetMissionData, | ||
} | ||
) | ||
|
||
// InitializeRemote function setup the library to be used | ||
func InitializeRemote(hostname string) { | ||
if len(hostname) > 0 { | ||
utils.SetHostname(hostname) | ||
} else { | ||
logger.LogInfo("Hostname omitted. Using localhost") | ||
} | ||
|
||
model.SetupTelemetry() | ||
errGroup = new(errgroup.Group) | ||
} | ||
|
||
func InitializeLocalHost() { | ||
InitializeRemote("127.0.0.1") | ||
} | ||
|
||
func getTelemetryData() error { | ||
|
||
for name, callback := range collectors { | ||
logger.LogInfo("running task to get %v data", name) | ||
errGroup.Go(callback) | ||
} | ||
|
||
return errGroup.Wait() | ||
} | ||
|
||
// GetTelemetryData function retrieves all telemetry data | ||
func GetTelemetryData() (data *model.TelemetryData, err error) { | ||
|
||
// Initialize struct | ||
data = &model.TelemetryData{} | ||
|
||
if fail := getTelemetryData(); fail != nil { | ||
return nil, fail | ||
} | ||
|
||
data.MapInfo = model.GetInstance().MapInfo | ||
data.Gamechat = model.GetInstance().Gamechat | ||
data.Indicators = model.GetInstance().Indicators | ||
data.State = model.GetInstance().State | ||
data.HudMessages = model.GetInstance().HudMessages | ||
data.MapObjects = model.GetInstance().MapObjects | ||
data.MissionInfo = model.GetInstance().MissionInfo | ||
|
||
return | ||
} |