Skip to content

Commit

Permalink
GetFloat32WithDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
effoeffi committed Apr 13, 2024
1 parent 7272d0e commit 2f9a604
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
lint:
golangci-lint run

test:
go test -count=1 ./...
# -cover coverage.
# -shuffle=on runs the tests in a random order.
# -race activates the data race detector.
# -vet=all runs go vet to identify significant problems. If go vet finds any problems, go test reports those and does not run the test binary.
# -failfast stops test execution when a given unit test fails. It allows tests executed in parallel to finish.
.PHONY: test
test: ## Go recompile and test with coverage
go test ./... -cover -shuffle=on -race -vet=all -failfast
6 changes: 3 additions & 3 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func GetIntWithDefault(key string, defaultValue int) int {
return res
}

func GetFloat64WithDefault(key string, defaultValue float64) float64 {
func GetFloat32WithDefault(key string, defaultValue float64) float64 {

value, exists := os.LookupEnv(key)
if !exists {
return defaultValue
}

res, err := strconv.ParseFloat(value, 64)
res, err := strconv.ParseFloat(value, 32)
if err != nil {
slog.Warn("failed to parse environment variable that should be float64. using default",
slog.Warn("failed to parse environment variable that should be float32. using default",
"error", err, "env key", key, "value", value, "default", defaultValue)
return defaultValue
}
Expand Down

0 comments on commit 2f9a604

Please sign in to comment.