caarlos0 / env

A simple, zero-dependencies library to parse environment variables into structs

Home Page:https://pkg.go.dev/github.com/caarlos0/env/v11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

env: no parser found for field "<FIELD>" of type "map[string]string

kotyara85 opened this issue · comments

Started after migrating to go 1.18

	if err := env.ParseWithFuncs(&cfg, map[reflect.Type]env.ParserFunc{
		reflect.TypeOf(map[string]string{}): func(v string) (interface{}, error) {
			slice := strings.Split(v, ",")
			ret := map[string]string{}
			for _, el := range slice {
				entry := strings.Split(el, "=")
				if len(entry) == 2 && entry[0] != "" && entry[1] != "" {
					key := strings.TrimSpace(entry[0])
					value := strings.TrimSpace(entry[1])
					ret[key] = value
				}
			}
			return ret, nil
		},
	}); err != nil {
		log.Fatal(err)
	}

I had another env.Parse which would trigger the error