{"action":"created","issue":{"url":"https://api.github.com/repos/revel/revel/issues/915","labels_url":"https://api.github.com/repos/revel/revel/issues/915/labels{/name}","comments_url":"https://api.github.com/repos/revel/revel/issues/915/comments","events_url":"https://api.github.com/repos/revel/revel/issues/915/events","html_url":"https://github.com/revel/revel/pull/915","id":65030468,"number":915,"title":"Controller add c.Finish method to allow user give a Result and break off action call stack.","user":{"login":"huacnlee","id":5518,"avatar_url":"https://avatars.githubusercontent.com/u/5518?v=3","gravatar_id":"","url":"https://api.github.com/users/huacnlee","html_url":"https://github.com/huacnlee","followers_url":"https://api.github.com/users/huacnlee/followers","following_url":"https://api.github.com/users/huacnlee/following{/other_user}","gists_url":"https://api.github.com/users/huacnlee/gists{/gist_id}","starred_url":"https://api.github.com/users/huacnlee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huacnlee/subscriptions","organizations_url":"https://api.github.com/users/huacnlee/orgs","repos_url":"https://api.github.com/users/huacnlee/repos","events_url":"https://api.github.com/users/huacnlee/events{/privacy}","received_events_url":"https://api.github.com/users/huacnlee/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/revel/revel/labels/%23controller","name":"#controller","color":"d4c5f9"},{"url":"https://api.github.com/repos/revel/revel/labels/%23filter","name":"#filter","color":"d4c5f9"},{"url":"https://api.github.com/repos/revel/revel/labels/discuss","name":"discuss","color":"eb6420"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/revel/revel/milestones/7","html_url":"https://github.com/revel/revel/milestones/v0.13","labels_url":"https://api.github.com/repos/revel/revel/milestones/7/labels","id":808476,"number":7,"title":"v0.13","description":null,"creator":{"login":"brendensoares","id":905501,"avatar_url":"https://avatars.githubusercontent.com/u/905501?v=3","gravatar_id":"","url":"https://api.github.com/users/brendensoares","html_url":"https://github.com/brendensoares","followers_url":"https://api.github.com/users/brendensoares/followers","following_url":"https://api.github.com/users/brendensoares/following{/other_user}","gists_url":"https://api.github.com/users/brendensoares/gists{/gist_id}","starred_url":"https://api.github.com/users/brendensoares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendensoares/subscriptions","organizations_url":"https://api.github.com/users/brendensoares/orgs","repos_url":"https://api.github.com/users/brendensoares/repos","events_url":"https://api.github.com/users/brendensoares/events{/privacy}","received_events_url":"https://api.github.com/users/brendensoares/received_events","type":"User","site_admin":false},"open_issues":48,"closed_issues":23,"state":"open","created_at":"2014-09-30T16:02:08Z","updated_at":"2015-09-23T19:54:49Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2015-03-29T06:37:05Z","updated_at":"2015-09-23T19:54:49Z","closed_at":"2015-09-23T19:54:49Z","pull_request":{"url":"https://api.github.com/repos/revel/revel/pulls/915","html_url":"https://github.com/revel/revel/pull/915","diff_url":"https://github.com/revel/revel/pull/915.diff","patch_url":"https://github.com/revel/revel/pull/915.patch"},"body":"Useful method to give a Result and break off action call stack.\r\n\r\n### For example:\r\n\r\nbefore:\r\n\r\n```go\r\nfunc (c Posts) requireUser() revel.Result {\r\n  if c.Session[\"user_id\"] == nil {\r\n    return c.Redirect(\"/login\")\r\n  }\r\n  return nil\r\n}\r\n\r\nfunc (c Posts) Edit() revel.Result {\r\n  if r := c.requireUser(); r != nil {\r\n    return r\r\n  }\r\n\r\n  posts := DB.FindPosts()\r\n  c.RenderArgs[\"posts\"] = posts\r\n  return c.Render()\r\n}\r\n```\r\n\r\nafter:\r\n\r\n```go\r\nfunc (c Posts) requireUser {\r\n  if c.Session[\"user_id\"] == nil {\r\n    c.Finish(c.Redirect(\"/login\"))\r\n  }\r\n}\r\n\r\nfunc (c Posts) Edit() revel.Result {\r\n  c.requireUser()\r\n  // Follow code will not run, if requireUser called c.Finish\r\n  posts := DB.FindPosts()\r\n  c.RenderArgs[\"posts\"] = posts\r\n  return c.Render()\r\n}\r\n```\r\n \r\n- No login: [GET /posts/1/edit] -> [Require user] -> [Redirect] -> [End]\r\n- Logined:  [GET /posts/1/edit] -> [Require user] -> [FindPosts] -> [Render] -> [End]\r\n\r\n----\r\n\r\nPS: Where is the controller test cases?\r\n"},"comment":{"url":"https://api.github.com/repos/revel/revel/issues/comments/142710673","html_url":"https://github.com/revel/revel/pull/915#issuecomment-142710673","issue_url":"https://api.github.com/repos/revel/revel/issues/915","id":142710673,"user":{"login":"brendensoares","id":905501,"avatar_url":"https://avatars.githubusercontent.com/u/905501?v=3","gravatar_id":"","url":"https://api.github.com/users/brendensoares","html_url":"https://github.com/brendensoares","followers_url":"https://api.github.com/users/brendensoares/followers","following_url":"https://api.github.com/users/brendensoares/following{/other_user}","gists_url":"https://api.github.com/users/brendensoares/gists{/gist_id}","starred_url":"https://api.github.com/users/brendensoares/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendensoares/subscriptions","organizations_url":"https://api.github.com/users/brendensoares/orgs","repos_url":"https://api.github.com/users/brendensoares/repos","events_url":"https://api.github.com/users/brendensoares/events{/privacy}","received_events_url":"https://api.github.com/users/brendensoares/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T19:54:49Z","updated_at":"2015-09-23T19:54:49Z","body":"@huacnlee I think this is a simple solution and I am tempted to merge it, but some good points have been made here about avoiding magic via conventions (e.g. this method will actually end the request if you call it). It's better/safer to explicitly return a value.\r\n\r\nAs far a a user auth filter, I would actually recommend a [`BEFORE` interceptor](https://revel.github.io/manual/interceptors.html) myself.\r\n\r\nI'm going to close this PR for now for these reasons. Thanks for contributing!"}}