text/template and preserving new lines from a struct field

46 views
Skip to first unread message

Joseph Lorenzini

unread,
Sep 17, 2016, 8:44:55 AM9/17/16
to golang-nuts
Hi all,

Say I have the following struct:

type Info struct {
       Summary string
       Desc    string
}

And this is the template string

tmplStr      = `Summary={{.Summary}}, Desc={{.Desc}}`

If the value of Desc has newlines, it looks like the template engine strips those out and replaces them with spaces. Is there any way to force the template engine to preserve the new lines?

Thanks,
Joe

Joseph Lorenzini

unread,
Sep 17, 2016, 8:59:48 AM9/17/16
to golang-nuts
Actually, the issue is not the template but my logger. The logger is writing to os.Stderr for some reason that's not preserving new lines but if i do fmt.Println then the new lines are preserved.  Pretty sure i've made a simple error here and need to investigate more.


Joe 
Reply all
Reply to author
Forward
0 new messages