package stdio import ( "fmt" "os" "strings" "time" ) // SettingWord is the environment word the node-engine composes a module's config value key into, in a process's // environment and in the module's slice of the tool runner's MESH_TOOL_ENV alike (design 47 H2 §781; H-A-370): // MESH_CONFIG_, the key upper-cased with '-' and '.' written '_', holding the value as text. func SettingWord(key string) string { return "MESH_CONFIG_" + strings.ToUpper(strings.NewReplacer("-", "_", ".", "_").Replace(key)) } // Setting is the module's config value key as the node-engine composed it, and whether it composed one: the one // settings reader of a process and a bundle (§781). func Setting(key string) (string, bool) { return os.LookupEnv(SettingWord(key)) } // SettingDuration is the config value key read as a Go duration ("10m"): def when none is composed or it is empty, an // error naming the key for a value that is no duration above zero. func SettingDuration(key string, def time.Duration) (time.Duration, error) { v, ok := Setting(key) if v = strings.TrimSpace(v); !ok || v == "" { return def, nil } d, err := time.ParseDuration(v) if err != nil || d <= 0 { return 0, fmt.Errorf("the setting %s (%s) holds %q, which is not a duration above zero", key, SettingWord(key), v) } return d, nil }