Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text/template: add break and continue support #20531

Closed
bep opened this issue May 30, 2017 · 12 comments
Closed

text/template: add break and continue support #20531

bep opened this issue May 30, 2017 · 12 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Proposal-Accepted
Milestone

Comments

@bep
Copy link
Contributor

bep commented May 30, 2017

This is a repost of #20523 with, hopefully, a more clear description.

Go templates currently do not support the break nor the continue keyword -- which surprises people trying a construct similar to the one below.

{{ range $i, $e := .SomeSlice }}
  {{ if gt $i 2 }}
    {{ break }}
  {{ end }}
  {{ $e }}
{{ end }}

/cc @igramnet

@odeke-em odeke-em changed the title text/template: Add break and continue support proposal: text/template: add break and continue support May 31, 2017
@gopherbot gopherbot added this to the Proposal milestone May 31, 2017
@odeke-em
Copy link
Member

/cc @rsc @robpike and other text/template folks.

@rsc
Copy link
Contributor

rsc commented Jun 5, 2017

It does seem a little reasonable. I wouldn't want labels (or goto), though. Thoughts, @robpike?

@robpike
Copy link
Contributor

robpike commented Jun 5, 2017

It does seem reasonable but low priority.

@rsc rsc changed the title proposal: text/template: add break and continue support text/template: add break and continue support Jun 12, 2017
@rsc rsc modified the milestones: Go1.10, Proposal Jun 12, 2017
@rsc
Copy link
Contributor

rsc commented Jun 12, 2017

CLs welcome for Go 1.10. Thanks.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/66410 mentions this issue: text/template: add break, continue actions in ranges

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/92155 mentions this issue: text/template: revert CL 66410 "add break, continue actions in ranges"

@robpike robpike reopened this Feb 6, 2018
@ianlancetaylor
Copy link
Contributor

The patch was rolled back, so reopening.

@ianlancetaylor ianlancetaylor reopened this Feb 6, 2018
@ALTree ALTree modified the milestones: Go1.10, Go1.11 Feb 7, 2018
@jimmyfrasche
Copy link
Member

This seems like an easy way to create goroutine leaks that weren't possible before since range can iterate over a channel.

@robpike
Copy link
Contributor

robpike commented Feb 15, 2018

@jimmyfrasche There are zillions of ways to create goroutine leaks. Adding one more doesn't seem to be that much of a change to the world.

@jimmyfrasche
Copy link
Member

@robpike Certainly true. I originally thought that this is different as, if the templates are user provided, it's a way for the provided template to cause the leak, but then I realized that the same goroutine leak could be caused by the template simply choosing to not range over the channel at all. Either way, it's up to the program running the template to ensure all chans are drained after execution.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Jun 29, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Unplanned Jun 29, 2018
@ALTree ALTree removed the Proposal label Sep 22, 2018
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/321491 mentions this issue: html/template, text/template: implement break and continue for range loops

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/373915 mentions this issue: doc/go1.18: document {text,html}/template {break,continue} commands

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Proposal-Accepted
Projects
None yet
Development

No branches or pull requests

9 participants