I’ve the following function which should be run in production I read some config If valid add the runner otherwise just return, the function is working! Is there a cleaner/better way to do it in go? error handling...


func (z *zmp) Add(val string, runner Runner) {
    vmap := viper.GetStringMap(val)
    if len(vmap) > 0 {
        if val, ok := configs["active"]; ok {
            if !val.(bool) {
                log.info(“not valid”)
  • \$\begingroup\$ Also: using viper, I'd not bother with manually checking my own map, doing all the type assertions etc... I'd use viper.SetDefault(key, values), where values can be a map, or a single value. I would also avoid relying on map[string]interface{} as much as possible, in favour of dedicated config types with json or yaml tags instead. \$\endgroup\$ Feb 3 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.