Upgrade to Pro — share decks privately, control downloads, hide ads and more …

text/template

 text/template

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.

More Decks by Joseph Anthony Pasquale Holsten

Other Decks in Programming

Transcript

  1. 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)
  2. - C K Ogden & I A Richards, 1923 The

    gostak destims the doshes
  3. // 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! }
  4. 2014-02: 1! 2013-12: 1! 2013-09: 4! 2013-08: 6! 2013-07: 3!

    2013-05: 1! 2013-03: 5! 2013-01: 2! 2012-10: 4! 2012-09: 3! 2012-08: 6! 2012-07: 4! 2012-06: 1! 2012-05: 1! 2012-09: 4! 2012-04: 3! 2012-06: 1! 2012-04: 6! 2012-03: 6! 2012-02: 10! 2012-01: 6! 2011-12: 5! 2011-11: 12 64 [email protected]! 4 [email protected]! 3 [email protected]! 3 [email protected]! 2 [email protected]! 2 [email protected]! 2 [email protected]! 2 [email protected]! 2 [email protected]! 2 [email protected]! 2 [email protected]! 1 [email protected]! 1 [email protected]! 1 [email protected]! 1 [email protected]! 1 [email protected]! 1 [email protected]! 1 [email protected]