erigon-pulse/erigon-lib/common/dbg/dbg_env.go
Alex Sharov eb4685f3e2
mode to produce block snapshots (#9053)
`STAGES_ONLY_BLOCKS=true` may help to produce BlockSnaps by Erigon2 on
weak machines - it disabling all stages after StageSenders.
2023-12-22 05:43:30 +00:00

58 lines
1.1 KiB
Go

package dbg
import (
"fmt"
"os"
"strconv"
"github.com/c2h5oh/datasize"
)
func EnvString(envVarName string, defaultVal string) string {
v, _ := os.LookupEnv(envVarName)
if v != "" {
fmt.Printf("[dbg] env %s=%s\n", envVarName, v)
return v
}
return defaultVal
}
func EnvBool(envVarName string, defaultVal bool) bool {
v, _ := os.LookupEnv(envVarName)
if v == "true" {
fmt.Printf("[dbg] env %s=%t\n", envVarName, true)
return true
}
if v == "false" {
fmt.Printf("[dbg] env %s=%t\n", envVarName, false)
return false
}
return defaultVal
}
func EnvInt(envVarName string, defaultVal int) int {
v, _ := os.LookupEnv(envVarName)
if v != "" {
i, err := strconv.Atoi(v)
if err != nil {
panic(err)
}
if i < 0 || i > 4 {
panic(i)
}
fmt.Printf("[dbg] env %s=%d\n", envVarName, i)
return i
}
return defaultVal
}
func EnvDataSize(envVarName string, defaultVal datasize.ByteSize) datasize.ByteSize {
v, _ := os.LookupEnv(envVarName)
if v != "" {
val, err := datasize.ParseString(v)
if err != nil {
panic(err)
}
fmt.Printf("[dbg] env %s=%s\n", envVarName, val)
return val
}
return defaultVal
}