On Saturday, October 14, 2023 at 3:47:54 PM UTC-4 Dan Kortschak wrote:

On Sat, 2023-10-14 at 09:33 -0700, Tong Sun wrote: 
> Please take a look at  
> https://go.dev/play/p/dTDR50dtHB0 
> 
> I want to 
> 
> - define my template data dynamically from yaml 
> - and export the yaml data if they are unexported 
> 
> I.e., for the following code: 
> 
> t := template.New("") 
> t, err = t.Parse("It's {{.A}} {{.B.C}}!\n") 
> if err != nil { 
> log.Fatalf("error: %v", err) 
> } 
> t.Execute(os.Stdout, m) 
> 
> The input is `map[A:Easy! B:map[C:2 D:[3 4]]]`. 
> But why the template was not able to produce any output for the 
> dynamic fields? 

It is trying to match a string to a main.MyKey. If the only reason you 
are using that type is to change the case of the key strings, I'd just 
index into the lowercase, https://go.dev/play/p/wi9KICK1zmW.


 wow, thanks.

Hmm... somehow I had the impression that only the exported fields can be 
used in template as variables.

Is that a wrong impression or things have changed?


-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8a2df85b-5d5a-4a9d-b0ae-8cc3d46b7aa3n%40googlegroups.com.

Reply via email to