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.

Transcript

  1. text/template

  2. /* Package template implements data- driven templates for generating textual

    output.
  3. Reading

  4. Usage

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

    gostak destims the doshes
  7. Correctness

  8. if! with! range! index! len call! printf! js! urlquery eq!

    ne! gt! le! ! and! not! or
  9. Seven Types of Ambiguity - William Empson, 1930

  10. Efficiency

  11. // 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! }
  12. • Referential • Aesthetic • Emotive • Conative • Phatic

    • Metalingual - Roman Jacobson, 1960
  13. Extend

  14. html/template

  15. Structure, Sign & Play - Jaques Derrida, 1966

  16. History

  17. 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 r@golang.org! 4 rsc@golang.org! 3 nigeltao@golang.org! 3 adg@golang.org! 2 yves.junqueira@gmail.com! 2 ugorji@gmail.com! 2 minux.ma@gmail.com! 2 matt.jibson@gmail.com! 2 josharian@gmail.com! 2 gri@golang.org! 2 dsymonds@golang.org! 1 oudomphe@phare.normalesup.org! 1 mikioh.mikioh@gmail.com! 1 khr@golang.org! 1 kamil@kamilkisiel.net! 1 jrh@joshh.co.uk! 1 gustavo@niemeyer.net! 1 elias.naur@gmail.com
  18. Qu’est-ce qu’un auteur? - Michel Foucault, 1967

  19. None