about summary refs log tree commit diff
path: root/environment.go
blob: e5baf2e58b15858d71ffc99216c229cc74b02e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main

import (
	"flag"
	"log"
	"os"
	"strconv"
)

func getEnvironment() {
	log.Println("[environment] Initializing the environment")
	getFlags()
	getEnvironmentVars()
}

func getEnvironmentVars() {
	log.Println("[ ] Getting the environment variables...")

	// get the data that should be used to connect to the database

	DISTRIBUTORURL = os.Getenv("DISTRIBUTORURL")
	if DISTRIBUTORURL == "" {
		DISTRIBUTORURL = "localhost:8081"
	}

	METRICBUNDLERURL = os.Getenv("METRICBUNDLERURL")
	if METRICBUNDLERURL == "" {
		METRICBUNDLERURL = "metrics-bundler.nbg1.emile.space"
	}

	DBURL = os.Getenv("DBURL")
	if DBURL == "" {
		DBURL = "postgresql.docker.localhost"
	}

	// get the data that should be used to connect to the database
	DBUSER = os.Getenv("DBUSER")
	if DBUSER == "" {
		DBUSER = "postgres"
	}

	DBPASSWD = os.Getenv("DBPASSWD")
	if DBPASSWD == "" {
		DBPASSWD = ""
	}

	DBPORT, _ := strconv.ParseInt(os.Getenv("DBPORT"), 10, 64)
	if DBPORT == 0 {
		DBPORT = 5432
	}

	DBNAME = os.Getenv("DBNAME")
	if DBNAME == "" {
		DBNAME = "postgres"
	}

	log.Println("--------------------")
	log.Printf("DBURL: %s", DBHOST)
	log.Printf("DBUSER: %s", DBUSER)
	log.Printf("DBPASSWD: %s", DBPASSWD)
	log.Printf("DBPORT: %d", DBPORT)
	log.Printf("DBPROJECTNAME: %s", DBNAME)
	log.Println("--------------------")
	log.Printf("DISTRIBUTORURL: %s", DISTRIBUTORURL)
	log.Printf("METRICBUNDLERURL: %s", METRICBUNDLERURL)
	log.Println("--------------------")
}

func getFlags() {
	// Parse the metricsPusherDelay from the command line.
	// If no argument is provided, the delay defaults at 5 seconds
	flag.Int64Var(&metricsPusherDelay, "metricsPusherDelay", 5, "The delay (in seconds) between the metric Pushes")
	flag.Parse()
	log.Println("[ ] Done loading the flags")
}