Open kataras opened 4 years ago
I have one more proposal, support aliases in the section names.
The current NameMapper
can only return a single name for keys (and not for sections, see SectionsByName
). I think we can add a new field named : AliasMapper = func(section string) []string { return []string{"iris."+ section} }
(PR: https://github.com/go-ini/ini/pull/265) . I need to map the keys either through root or a child if the Iris Configuration was embedded as a field in a custom end-developer's struct.
Hi @kataras, thanks for investigating into this!
I manage to get it work by applying the following diff:
type TunnelingConfiguration struct {
WebInterface string `ini:"web_interface"`
- Tunnels. []Tunnel `ini:"tunnels"`
+ Tunnels []Tunnel `ini:"tunneling.tunnels,,,nonunique"`
}
I know this is very very unintuitive 😅 and the "nonunique" part is undocumented...
Hello @unknwon That's awesome, I didn't even notice that in the code.
OK, one problem solved. We have two more issues to solve and we are ready to go:
net.IP
is not possible. How we can solve it? The net.IP
completes the TextUnmarshaller interface. This allows us to read it as string before trying to read it as a slice of uint8. So a support of TextUnmarshaller
on that kind of packages is a MUST I think.map type
not supported. That leads people to add custom binders for each type of map, e.g. map[string]string, map[string]bool, map[string]interface{}
.Also note that the AliasMapper
is still necessary because we need to match sections like [iris.tunneling.tunnels]
and [tunneling.tunnels]
(when the end-developer didn't specified a parent of iris).
@kataras Thanks for the follow up!
I suggest to file separate issues for better tracking :)
I stumbled upon this, too; but for my usecase the "nonunique" declaration helped. Thanks alot!
Hello @unknwon,
I am thinking to add support for loading from
.ini
for Iris Configuration and custom configurations. So far we have support for json, yaml and toml and they're working fine. I have a problem though, while trying to read a config file to theiris.Configuration
structure, I have defined theini
fields, I triedallowShadow
with customini.LoaderOptions
but that doesn't work either. Code speaks by itself:I tried plenty of ini formats but I would love to support something like that (if already exists, I couldn't find it):
How I load
So even if
AllowNonUniqueSections
is true, theTunnels
are never binded to thedest
one.I did manage to do it by using this code,befoer StrictMapTo:
Is there a way to do that mapping automatically or it's a planned feature? I think would be trivial to do that, you already collecting multi sections of the same key under a section, so why not add support for appending them to the corresponding field?
Thanks, Gerasimos Maropoulos.