Skip to content

Commit

Permalink
chore: ⚡ implements specific setup methods for localhost and remote host
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Vieira <lucas.engen.cc@gmail.com>
  • Loading branch information
lucasvmx committed May 10, 2024
1 parent cdb6623 commit 5cddc50
Showing 1 changed file with 70 additions and 66 deletions.
136 changes: 70 additions & 66 deletions telemetry/telemetry.go
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
}

0 comments on commit 5cddc50

Please sign in to comment.