fix funtion
This commit is contained in:
parent
2168404670
commit
b36ab9e572
29
main.go
29
main.go
|
|
@ -9,26 +9,30 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getConfigFromEnv(item string) {
|
func getConfigFromEnv(item string) string {
|
||||||
var res = ""
|
var res = ""
|
||||||
value := os.Getenv("CONFIG_ENVVAR")
|
value := os.Getenv("CONFIG_ENVVAR")
|
||||||
if value == "" {
|
if value == "" {
|
||||||
value = "ADDRESS,INITIALCOST,MONTHLYCOST"
|
value = "ADDRESS,INITIALCOST,MONTHLYCOST"
|
||||||
}
|
}
|
||||||
configarr = strings.Split(value, ",")
|
configArr := strings.Split(value, ",")
|
||||||
if len(configarr) < 3 {
|
|
||||||
|
// Check for expected length to prevent out-of-range panic
|
||||||
|
if len(configArr) < 3 {
|
||||||
logit("CONFIG_ENVVAR has less than 3 elements")
|
logit("CONFIG_ENVVAR has less than 3 elements")
|
||||||
|
return "NOTFOUND"
|
||||||
}
|
}
|
||||||
if item == "address" {
|
|
||||||
res = configarr[0]
|
switch strings.ToLower(item) {
|
||||||
} else if item == "initialcost" {
|
case "address":
|
||||||
res = configarr[1]
|
return configArr[0]
|
||||||
} else if item == "monthlycost" {
|
case "initialcost":
|
||||||
res = configarr[2]
|
return configArr[1]
|
||||||
} else {
|
case "monthlycost":
|
||||||
res = "NOTFOUND"
|
return configArr[2]
|
||||||
|
default:
|
||||||
|
return "NOTFOUND"
|
||||||
}
|
}
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -91,7 +95,6 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
Address string
|
Address string
|
||||||
InitialCost string
|
InitialCost string
|
||||||
MonthlyCost string
|
MonthlyCost string
|
||||||
Address string
|
|
||||||
Scales []string
|
Scales []string
|
||||||
LastMetrics []OneMetric
|
LastMetrics []OneMetric
|
||||||
QueryValues map[string][]string
|
QueryValues map[string][]string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue