We deal with text every day. I'll show you how to use text/template to convert your data into whatever representation you'd like, but I'd also like to talk about how we read code, using text/template as a source text.
type Inventory struct { Material string Count uint } sweaters := Inventory{"wool", 17} tmpl, _ := template.New(“test"). Parse("{{.Count}} items are made of {{.Material}}") tmpl.Execute(os.Stdout, sweaters)
// lex creates a new scanner for the input string.! func lex(name, input, left, right string) *lexer {! if left == "" {! left = leftDelim! }! if right == "" {! right = rightDelim! }! l := &lexer{! name: name,! input: input,! leftDelim: left,! rightDelim: right,! items: make(chan item),! }! go l.run()! return l! }