On Wed, May 2, 2018 at 11:47 AM, Burak Serdar wrote:
> >> > // now
> >> > env := make(map[string]string)
> >> > for _, e := range os.Environ() {
> >> > sep := strings.Index(e, "=")
> >> > env[e[0:sep]] = e[sep+1:]
> >> > }
> >> > // how to add env into data as ENV so that it can be accessed within
> >>
> >> args:=map[string]interface{}{"ENV":env}
> >> generic(templateStr,args)
> >
> >
> > It looks to me that the above code just pass env (only) to generic,
> instead
> > of adding into data.
>
> Sorry, I didn't look at the code you have in the playground.
>
> You're passing:
>
> sweaters := Inventory{"wool", 17}
> generic("{{.Count}} items are made of {{.Material}}\n", sweaters)
>
> You can't add "ENV" to an "Inventory" unless it is already a part of
> it. With this code, you're passing in only one Inventory instance.
> Template evaluation can only access the public names in that struct,
> so you can't add more.
I'm trying to provide a *general *library that take an arbitrary data, so
I'd not to ask lib user to add that ENV part *if possible*.
If the text Template library can deal with arbitrary data, I think there
should be a way for my general library to do as well, but I just don't know
how. Is the following the magic spell?
value, ok := data.(reflect.Value)
Thanks for your help anyway.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.