{"action":"created","issue":{"url":"https://api.github.com/repos/labstack/echo/issues/525","repository_url":"https://api.github.com/repos/labstack/echo","labels_url":"https://api.github.com/repos/labstack/echo/issues/525/labels{/name}","comments_url":"https://api.github.com/repos/labstack/echo/issues/525/comments","events_url":"https://api.github.com/repos/labstack/echo/issues/525/events","html_url":"https://github.com/labstack/echo/issues/525","id":156751716,"number":525,"title":"[Proposal] Improve Context Response Options for Speed and Usability","user":{"login":"Anon-Penguin","id":7022869,"avatar_url":"https://avatars.githubusercontent.com/u/7022869?v=3","gravatar_id":"","url":"https://api.github.com/users/Anon-Penguin","html_url":"https://github.com/Anon-Penguin","followers_url":"https://api.github.com/users/Anon-Penguin/followers","following_url":"https://api.github.com/users/Anon-Penguin/following{/other_user}","gists_url":"https://api.github.com/users/Anon-Penguin/gists{/gist_id}","starred_url":"https://api.github.com/users/Anon-Penguin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anon-Penguin/subscriptions","organizations_url":"https://api.github.com/users/Anon-Penguin/orgs","repos_url":"https://api.github.com/users/Anon-Penguin/repos","events_url":"https://api.github.com/users/Anon-Penguin/events{/privacy}","received_events_url":"https://api.github.com/users/Anon-Penguin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/labstack/echo/labels/enhancement","name":"enhancement","color":"eb6420"}],"state":"open","locked":false,"assignee":{"login":"vishr","id":314036,"avatar_url":"https://avatars.githubusercontent.com/u/314036?v=3","gravatar_id":"","url":"https://api.github.com/users/vishr","html_url":"https://github.com/vishr","followers_url":"https://api.github.com/users/vishr/followers","following_url":"https://api.github.com/users/vishr/following{/other_user}","gists_url":"https://api.github.com/users/vishr/gists{/gist_id}","starred_url":"https://api.github.com/users/vishr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vishr/subscriptions","organizations_url":"https://api.github.com/users/vishr/orgs","repos_url":"https://api.github.com/users/vishr/repos","events_url":"https://api.github.com/users/vishr/events{/privacy}","received_events_url":"https://api.github.com/users/vishr/received_events","type":"User","site_admin":false},"assignees":[{"login":"vishr","id":314036,"avatar_url":"https://avatars.githubusercontent.com/u/314036?v=3","gravatar_id":"","url":"https://api.github.com/users/vishr","html_url":"https://github.com/vishr","followers_url":"https://api.github.com/users/vishr/followers","following_url":"https://api.github.com/users/vishr/following{/other_user}","gists_url":"https://api.github.com/users/vishr/gists{/gist_id}","starred_url":"https://api.github.com/users/vishr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vishr/subscriptions","organizations_url":"https://api.github.com/users/vishr/orgs","repos_url":"https://api.github.com/users/vishr/repos","events_url":"https://api.github.com/users/vishr/events{/privacy}","received_events_url":"https://api.github.com/users/vishr/received_events","type":"User","site_admin":false}],"milestone":null,"comments":5,"created_at":"2016-05-25T13:32:21Z","updated_at":"2016-08-06T18:19:28Z","closed_at":null,"body":"A few things I've noticed:\r\n\r\n1. There's no custom content type response function in the context, so people are limited to the handful of content types you've selected.\r\n2. As for the HTTP bodies, you have poor handling of strings vs byte slices. This is bad for performance, as there are a few times where I'd need to convert to a string for echo to convert it directly back to a `[]byte`, only for the correct content type.\r\n3. As far as I know, fasthttp's setup allows it to write strings with no overhead compared to bytes, so it's best to use the fasthttp function that accepts a string for speed.\r\n\r\nSo, formal proposal to fix these things:\r\n\r\n## Add new response options\r\n\r\n```go\r\n// Current functions for context interface:\r\nBind(interface{}) error\r\nRender(int, string, interface{}) error\r\nFile(string) error\r\nAttachment(io.ReadSeeker, string) error\r\nNoContent(int) error\r\nRedirect(int, string) error\r\n\r\nJSON(int, interface{}) error\r\nJSONBlob(int, []byte) error\r\nJSONP(int, string, interface{}) error\r\nXML(int, interface{}) error\r\nXMLBlob(int, []byte) error\r\n\r\n// =============================================\r\n\r\n// Deprecate this function in favor of HTMLString():\r\nHTML(int, string) error\r\n// Deprecate this function in favor of PlainTextString():\r\nString(int, string) error\r\n\r\n// =============================================\r\n\r\n// New, proposed functions for context interface:\r\nCustomContentBlob(int, string, []byte) // Second argument is content type\r\nCustomContentString(int, string, string) // Second argument is content type\r\n\r\nHTMLBlob(int, []byte) error\r\nHTMLString(int, string) error\r\n\r\nJSONString(int, string) error\r\n\r\nJSONPBlob(int, string, []byte) error\r\nJSONPString(int, string, string) error\r\n\r\nPlainTextString(int, string) error\r\nPlainTextBlob(int, []byte) error\r\n\r\nXMLString(int, string) error\r\n```\r\n\r\nThis way, for a response type `Foo`, an interface{} would be passed to `Foo()`, a string would be passed to `FooString()`, and a []byte would be passed to `FooBlob()`.\r\n\r\nIt's not the cleanest, but it's the most consistent I could get it without breaking anything.\r\n\r\n## Add a WriteString() function to each engine's `response.go` file\r\n\r\nOn fasthttp, this function will use [`response.WriteString()`](https://godoc.org/github.com/valyala/fasthttp#RequestCtx.WriteString). On standard, we will just cast using `[]byte(inputString)`.\r\n"},"comment":{"url":"https://api.github.com/repos/labstack/echo/issues/comments/238037674","html_url":"https://github.com/labstack/echo/issues/525#issuecomment-238037674","issue_url":"https://api.github.com/repos/labstack/echo/issues/525","id":238037674,"user":{"login":"Anon-Penguin","id":7022869,"avatar_url":"https://avatars.githubusercontent.com/u/7022869?v=3","gravatar_id":"","url":"https://api.github.com/users/Anon-Penguin","html_url":"https://github.com/Anon-Penguin","followers_url":"https://api.github.com/users/Anon-Penguin/followers","following_url":"https://api.github.com/users/Anon-Penguin/following{/other_user}","gists_url":"https://api.github.com/users/Anon-Penguin/gists{/gist_id}","starred_url":"https://api.github.com/users/Anon-Penguin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Anon-Penguin/subscriptions","organizations_url":"https://api.github.com/users/Anon-Penguin/orgs","repos_url":"https://api.github.com/users/Anon-Penguin/repos","events_url":"https://api.github.com/users/Anon-Penguin/events{/privacy}","received_events_url":"https://api.github.com/users/Anon-Penguin/received_events","type":"User","site_admin":false},"created_at":"2016-08-06T18:19:28Z","updated_at":"2016-08-06T18:19:28Z","body":"I agree that it's more hack-ish. However, unless we want to break compatibility, our only options are:\r\n\r\n- A new name (`CustomContentBlob`/`CustomContentString` or something else with that name)\r\n- Var args"}}
{"actor":{"display_login":"Anon-Penguin"}}