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

auto parameters disables autorendering causing a blank page #2979

Closed
TankTheFrank opened this issue Dec 14, 2017 · 1 comment
Closed

auto parameters disables autorendering causing a blank page #2979

TankTheFrank opened this issue Dec 14, 2017 · 1 comment

Comments

@TankTheFrank
Copy link

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go and beego are you using (bee version)?

go 1.9.2
beego 1.9.0

  1. What operating system and processor architecture are you using (go env)?
    darwin/amd64

  2. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.

Added an auto-parameter method to a controller instead of an empty method/Ctx.Input.Param way.

Using this:

// @router /:id [get]
func (c *MyController) Show(id int64) {
}

outputs nothing - auto template rendering is ignored. Adding c.Render() shows the expected output.

Changing it to "old way" also renders the template.

// @router /:id [get]
func (c *MyController) Show() {
id := c.Ctx.Input.Param(":id")
}

  1. What did you expect to see?

The template rendered

  1. What did you see instead?

Nothing, 0 bytes

@TankTheFrank
Copy link
Author

TankTheFrank commented Dec 14, 2017

I believe the issue is here, correct me if I'm wrong:

https://github.com/astaxie/beego/blob/bf5c5626ab429e66d88602e1ab1ab5fbf4629a01/router.go#L951-L963

The idea is to disable the render if we have some kind of 'result' from a custom HandlerFunc (not a post, get, put, etc method). But there is no check if there is actually output a custom method before setting the status to 200 which in turn blocks the renderer. So the fix should be changing

if !context.ResponseWriter.Started && context.Output.Status == 0 { context.Output.SetStatus(200) }

with
if !context.ResponseWriter.Started && len(results) > 0 && context.Output.Status == 0 { context.Output.SetStatus(200) }

I'll open a pull request unless I'm missing something about the logic.

TankTheFrank pushed a commit to TankTheFrank/beego that referenced this issue Dec 14, 2017
TankTheFrank added a commit to TankTheFrank/beego that referenced this issue Dec 14, 2017
TankTheFrank pushed a commit to TankTheFrank/beego that referenced this issue Dec 14, 2017
astaxie added a commit that referenced this issue Jul 20, 2018
…utomatic_parameter_routing

fixes template rendering with automatic mapped parameters (see #2979)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant