diff options
| author | Rob Pike <r@golang.org> | 2012-10-07 07:15:11 +1100 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-10-07 07:15:11 +1100 |
| commit | 421b75c0dbab3460dbfdb023d67ce0807c4d5327 (patch) | |
| tree | 6ea559c97ddf5d9743fb83a375dd15051cda0885 /src/pkg/text/template/parse | |
| parent | bbccfddb84473c10e95b1b80f8c6f68a8238a7d5 (diff) | |
| download | go-421b75c0dbab3460dbfdb023d67ce0807c4d5327.tar.xz | |
text/template: add an unexported method to Node
Protects the package a little against undesirable clients.
R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/6624054
Diffstat (limited to 'src/pkg/text/template/parse')
| -rw-r--r-- | src/pkg/text/template/parse/node.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/pkg/text/template/parse/node.go b/src/pkg/text/template/parse/node.go index 0cb7ceff4d..9d0d09eb5f 100644 --- a/src/pkg/text/template/parse/node.go +++ b/src/pkg/text/template/parse/node.go @@ -13,7 +13,9 @@ import ( "strings" ) -// A node is an element in the parse tree. The interface is trivial. +// A Node is an element in the parse tree. The interface is trivial. +// The interface contains an unexported method so that only +// types local to this package can satisfy it. type Node interface { Type() NodeType String() string @@ -22,6 +24,8 @@ type Node interface { // CopyXxx methods that return *XxxNode. Copy() Node Position() Pos // byte position of start of node in full original input string + // Make sure only functions in this package can create Nodes. + unexported() } // NodeType identifies the type of a parse tree node. @@ -35,6 +39,11 @@ func (p Pos) Position() Pos { return p } +// unexported keeps Node implementations local to the package. +// All implementations embed Pos, so this takes care of it. +func (Pos) unexported() { +} + // Type returns itself and provides an easy default implementation // for embedding in a Node. Embedded in all non-trivial Nodes. func (t NodeType) Type() NodeType { |
