config icon indicating copy to clipboard operation
config copied to clipboard

Panic on missing key/value

Open gabrieleiannetti opened this issue 3 years ago • 1 comments

Hi,

is there any support for panic on missing config keys and values?

Right now I have a wrapper code that calls the config tool with direct reads to accomplish that:

// Code snippet for panic on missing key/value
func (*ConfigFileReader) MustHaveString(key string) string {
	value := config.String(key)

	if len(value) == 0 {
		log.Panic("Config file key not found or has no value: ", key)
	}

	return value
}

Best Gabriele

gabrieleiannetti avatar Jan 18 '23 13:01 gabrieleiannetti

Oh ... you suggestion add like: MustString(), MustInt() ?

inhere avatar Feb 01 '23 16:02 inhere