all repos — gomponents @ f277d1942e9f2ec1ff4a3bc3c409e864103b506b

HTML components in pure Go

Pass attributes as pointers (#37)

Markus Wüstenberg
commit

f277d1942e9f2ec1ff4a3bc3c409e864103b506b

parent

3df42084aed213fc9e760b53b5132da63b1818b7

1 file changed, 5 insertions(+), 5 deletions(-)

changed files
M gomponents.gogomponents.go
@@ -114,9 +114,9 @@ // Use this if no convenience creator exists.
func Attr(name string, value ...string) Node { switch len(value) { case 0: - return attr{name: name} + return &attr{name: name} case 1: - return attr{name: name, value: &value[0]} + return &attr{name: name, value: &value[0]} default: panic("attribute must be just name or name and value pair") }
@@ -127,19 +127,19 @@ name string
value *string } -func (a attr) Render() string { +func (a *attr) Render() string { if a.value == nil { return fmt.Sprintf(" %v", a.name) } return fmt.Sprintf(` %v="%v"`, a.name, *a.value) } -func (a attr) Place() Placement { +func (a *attr) Place() Placement { return Inside } // String satisfies fmt.Stringer. -func (a attr) String() string { +func (a *attr) String() string { return a.Render() }