Skip to content

Commit

Permalink
Merge pull request #3 from lettdigital/new_way_o_get_envs
Browse files Browse the repository at this point in the history
removendo flags
  • Loading branch information
alexsanderp committed Mar 26, 2021
2 parents 3e325e5 + 7da91b7 commit d3a7892
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,15 @@ import (
)

var (
listenAddress = flag.String("listen", ":9108", "Listen address for prometheus")
metricsPath = flag.String("path", "/metrics", "Path under which to expose metrics")
updateIntervalPointer = flag.Int64("interval", 600, "Queue update interval, seconds")
tagTeamPointer = flag.String("tags", "", "Allows you to filter the queues based on the desired tag")
listenAddress = flag.String("listen", ":9108", "Listen address for prometheus")
metricsPath = flag.String("path", "/metrics", "Path under which to expose metrics")
)

func main() {
flag.Parse()

tagTeam := *tagTeamPointer
updateInterval := *updateIntervalPointer

if len(os.Getenv("INTERVAL")) > 0 {
if i, err := strconv.ParseInt(os.Getenv("INTERVAL"), 10, 64); err == nil {
updateInterval = i
}
}
flag.Parse()

if len(os.Getenv("TAGS")) > 0 {
tagTeam = os.Getenv("TAGS")
}
tagTeam, updateInterval := getEnvs()

ctx, cancel := context.WithCancel(context.Background())

Expand All @@ -62,4 +50,23 @@ func main() {
cancel()
log.Fatal(err)
}

}

func getEnvs() (string, int64) {

tagTeam := getOrPanic("TAG_TEAM")
interval, _ := strconv.ParseInt(getOrPanic("INTERVAL"), 10, 64)

return tagTeam, interval
}

func getOrPanic(env string) string {
value := os.Getenv(env)

if value == "" {
log.Panicf("Error loading envioment:: %v", value)
}

return value
}

0 comments on commit d3a7892

Please sign in to comment.