Skip to content

Commit

Permalink
feat: rewrite if-else to switch statement (#1000)
Browse files Browse the repository at this point in the history
Signed-off-by: Engin Diri <[email protected]>
  • Loading branch information
dirien authored Sep 29, 2024
1 parent 8e69a41 commit d5ed482
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const (
Namespace = "minecraft"
Forge = "forge"
PaperMC = "papermc"
Fabric = "fabric"
Fabric = "fabric"
PurpurMC = "purpurmc"
rconListCommand = "list"
rconForgeTpsCommand = "forge tps"
rconForgeEntityListCommand = "forge entity list"
rconTpsCommand = "tps"
rconFabricTpsCommand = "fabric tps"
rconFabricTpsCommand = "fabric tps"
)

// See for all details on the statistics of Minecraft https://minecraft.fandom.com/wiki/Statistics
Expand All @@ -48,7 +48,7 @@ type Exporter struct {
entityListRegexp *regexp.Regexp
paperMcTpsRegexp *regexp.Regexp
purpurMcTpsRegexp *regexp.Regexp
fabricMcTpsRegexp *regexp.Regexp

// via advancements
// playerAdvancements *prometheus.Desc

Expand Down Expand Up @@ -779,7 +779,8 @@ func parseFloat64FromString(value string) float64 {
}

func (e *Exporter) getServerStats(ch chan<- prometheus.Metric) (retErr error) {
if e.serverStats == Forge {
switch e.serverStats {
case Forge:
resp, err := e.executeRCONCommand(rconForgeTpsCommand)
if err != nil {
return err
Expand Down Expand Up @@ -815,8 +816,7 @@ func (e *Exporter) getServerStats(ch chan<- prometheus.Metric) (retErr error) {
ch <- prometheus.MustNewConstMetric(e.entities, prometheus.CounterValue, entityCounter, namespace, entityType)
}
}

} else if e.serverStats == PaperMC || e.serverStats == PurpurMC {
case PaperMC, PurpurMC:
resp, err := e.executeRCONCommand(rconTpsCommand)
if resp != nil {
if err != nil {
Expand Down Expand Up @@ -847,7 +847,7 @@ func (e *Exporter) getServerStats(ch chan<- prometheus.Metric) (retErr error) {
}
}
}
} else if e.serverStats == Fabric {
case Fabric:
resp, err := e.executeRCONCommand(rconFabricTpsCommand)
if err != nil {
return err
Expand Down

0 comments on commit d5ed482

Please sign in to comment.