[#493] node/config: Implement string caster

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-21 15:50:24 +03:00 committed by Leonard Lyubich
parent 7e11bf9a55
commit cbe3e0a271
4 changed files with 45 additions and 1 deletions

View file

@ -28,3 +28,22 @@ func StringSlice(c *Config, name string) []string {
func StringSliceSafe(c *Config, name string) []string {
return cast.ToStringSlice(c.Value(name))
}
// String reads configuration value
// from c by name and casts it to string.
//
// Panics if value can not be casted.
func String(c *Config, name string) string {
x, err := cast.ToStringE(c.Value(name))
panicOnErr(err)
return x
}
// StringSafe reads configuration value
// from c by name and casts it to string.
//
// Returns "" if value can not be casted.
func StringSafe(c *Config, name string) string {
return cast.ToString(c.Value(name))
}