{"action":"created","issue":{"url":"https://api.github.com/repos/kataras/iris/issues/165","repository_url":"https://api.github.com/repos/kataras/iris","labels_url":"https://api.github.com/repos/kataras/iris/issues/165/labels{/name}","comments_url":"https://api.github.com/repos/kataras/iris/issues/165/comments","events_url":"https://api.github.com/repos/kataras/iris/issues/165/events","html_url":"https://github.com/kataras/iris/issues/165","id":158010068,"number":165,"title":"Enhance router to allow string based lookups","user":{"login":"ryanbyyc","id":2421110,"avatar_url":"https://avatars.githubusercontent.com/u/2421110?v=3","gravatar_id":"","url":"https://api.github.com/users/ryanbyyc","html_url":"https://github.com/ryanbyyc","followers_url":"https://api.github.com/users/ryanbyyc/followers","following_url":"https://api.github.com/users/ryanbyyc/following{/other_user}","gists_url":"https://api.github.com/users/ryanbyyc/gists{/gist_id}","starred_url":"https://api.github.com/users/ryanbyyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryanbyyc/subscriptions","organizations_url":"https://api.github.com/users/ryanbyyc/orgs","repos_url":"https://api.github.com/users/ryanbyyc/repos","events_url":"https://api.github.com/users/ryanbyyc/events{/privacy}","received_events_url":"https://api.github.com/users/ryanbyyc/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/kataras/iris/labels/feature%20has%20implemented","name":"feature has implemented","color":"d4c5f9"},{"url":"https://api.github.com/repos/kataras/iris/labels/feature%20request","name":"feature request","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-01T21:21:53Z","updated_at":"2016-06-02T16:48:38Z","closed_at":null,"body":"What I propose is enhancing the routing system to allow for name based lookups. Currently, Iris routes are declared similarly to this:\r\n```go\r\nfunc exampleRoutes(api *iris.Iris) {\r\n\tparty := api.Party(\"/p/:username\")\r\n\t{\r\n\t\tparty.Handle(\"GET\", \"/\", profile.ProfileHandler)\r\n    party.Handle(\"GET\", \"/friends/:page\", profile.FriendsHandler)\r\n    party.Handle(\"GET\", \"/images\", profile.ImagesHandler)\r\n\t}\r\n  api.Handle(\"GET\", \"/\", index.IndexHandler)\r\n}\r\n```\r\n\r\nWhat I would like to see is the ability to name routes so they can be referenced later.\r\n\r\n```go\r\nfunc exampleRoutes(api *iris.Iris) {\r\n\tparty := api.Party(\"/p/:username\").Prefix(\"profile\")\r\n\t{\r\n\t\tparty.Handle(\"GET\", \"/\", profile.ProfileHandler).Name(\"index\")\r\n    party.Handle(\"GET\", \"/friends/:page\", profile.FriendsHandler).Name(\"friends\")\r\n    party.Handle(\"GET\", \"/images\", profile.ImagesHandler).Name(\"images\")\r\n\t}\r\n  api.Handle(\"GET\", \"/\", index.IndexHandler).Name(\"index\")\r\n}\r\n```\r\n\r\nWhen a party is used, it should combine the Prefix and name (delimited by \"-\") to build the name. If no prefix is used, try to register the route name but error out on name collisions.\r\n\r\nThen I'd like to do this via template functions, within ``*iris.Context` or using a route \"getter\" method. For instance, something like: `{{ urlTo \"profile-friends\" user.Username}}`\r\n\r\nIt would also be great if each route knew of its own parameters, so that each parameter could be overwritten, or inherited. For the \"profile-friends\" group, that might look like this:\r\n* Inherited: `{{ urlTo \"profile-friends\" .page}}` (assumes that the route knows `:username`)\r\n* Overwritten: `{{ urlTo \"profile-friends\" .User.Username 1}}`\r\n\r\nAlso, create a helper to get the current route name. This would allow for things like:\r\n`<li {{ if eq currentRouteName \"profile-friends\"}}class=\"active\"{{end}}><a href=\"{{ currentRoute }}#friends\">Friends</a></li>`\r\nOr:\r\n`<li {{ if eq currentRouteParty \"profile\"}}class=\"expanded\"{{end}}>{{ .Username}}</li>`\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/34781554-enhance-router-to-allow-string-based-lookups?utm_campaign=plugin&utm_content=tracker%2F30189074&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F30189074&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/kataras/iris/issues/comments/223351674","html_url":"https://github.com/kataras/iris/issues/165#issuecomment-223351674","issue_url":"https://api.github.com/repos/kataras/iris/issues/165","id":223351674,"user":{"login":"kataras","id":2321588,"avatar_url":"https://avatars.githubusercontent.com/u/2321588?v=3","gravatar_id":"","url":"https://api.github.com/users/kataras","html_url":"https://github.com/kataras","followers_url":"https://api.github.com/users/kataras/followers","following_url":"https://api.github.com/users/kataras/following{/other_user}","gists_url":"https://api.github.com/users/kataras/gists{/gist_id}","starred_url":"https://api.github.com/users/kataras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kataras/subscriptions","organizations_url":"https://api.github.com/users/kataras/orgs","repos_url":"https://api.github.com/users/kataras/repos","events_url":"https://api.github.com/users/kataras/events{/privacy}","received_events_url":"https://api.github.com/users/kataras/received_events","type":"User","site_admin":false},"created_at":"2016-06-02T16:48:37Z","updated_at":"2016-06-02T16:48:37Z","body":"More features on this: \r\n\r\n-  ` iris.RouteByName(\"my-page1\").GetURI()` prints the full uri with scheme http:// or https:// the full host, port and the path.\r\n\r\n- ` context.RedirectTo(\"my-page1\", ...optional parameters for dynamic routes here)` \r\n\r\n\r\n"}}
{"actor":{"display_login":"kataras"}}