forked from kuskoman/logstash-exporter
-
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.
Split helpers package into prometheus_helper and config functions
- Loading branch information
Showing
14 changed files
with
72 additions
and
129 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
func InitializeEnv() error { | ||
return godotenv.Load() | ||
} | ||
|
||
func getEnvWithDefault(key string, defaultValue string) string { | ||
value := os.Getenv(key) | ||
if value == "" { | ||
return defaultValue | ||
} | ||
return value | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetEnvWithDefault(t *testing.T) { | ||
t.Run("should return value for set environment variable", func(t *testing.T) { | ||
key := "TEST3" | ||
expected := "value" | ||
os.Setenv(key, expected) | ||
actual := getEnvWithDefault(key, "default") | ||
if actual != expected { | ||
t.Errorf("expected %s but got %s", expected, actual) | ||
} | ||
}) | ||
|
||
t.Run("should return default value for unset environment variable", func(t *testing.T) { | ||
expected := "default" | ||
actual := getEnvWithDefault("TEST_UNSET3", expected) | ||
if actual != expected { | ||
t.Errorf("expected %s but got %s", expected, actual) | ||
} | ||
}) | ||
} |
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,7 +1,5 @@ | ||
package config | ||
|
||
import "github.com/kuskoman/logstash-exporter/helpers" | ||
|
||
var ( | ||
LogstashUrl = helpers.GetEnvWithDefault("LOGSTASH_URL", "http://localhost:9600") | ||
LogstashUrl = getEnvWithDefault("LOGSTASH_URL", "http://localhost:9600") | ||
) |
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,8 +1,6 @@ | ||
package config | ||
|
||
import "github.com/kuskoman/logstash-exporter/helpers" | ||
|
||
var ( | ||
Port = helpers.GetEnvWithDefault("PORT", "9198") | ||
Host = helpers.GetEnvWithDefault("HOST", "") | ||
Port = getEnvWithDefault("PORT", "9198") | ||
Host = getEnvWithDefault("HOST", "") | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
helpers/prometheus_helper.go → prometheus_helper/prometheus_helper.go
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,4 +1,4 @@ | ||
package helpers | ||
package prometheus_helper | ||
|
||
import ( | ||
"errors" | ||
|
2 changes: 1 addition & 1 deletion
2
helpers/prometheus_helper_test.go → prometheus_helper/prometheus_helper_test.go
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,4 +1,4 @@ | ||
package helpers | ||
package prometheus_helper | ||
|
||
import ( | ||
"fmt" | ||
|