{"action":"created","issue":{"url":"https://api.github.com/repos/wantedly/apig/issues/85","repository_url":"https://api.github.com/repos/wantedly/apig","labels_url":"https://api.github.com/repos/wantedly/apig/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/wantedly/apig/issues/85/comments","events_url":"https://api.github.com/repos/wantedly/apig/issues/85/events","html_url":"https://github.com/wantedly/apig/issues/85","id":173103944,"number":85,"title":"panic: runtime error: index out of range","user":{"login":"munisystem","id":7877005,"avatar_url":"https://avatars.githubusercontent.com/u/7877005?v=3","gravatar_id":"","url":"https://api.github.com/users/munisystem","html_url":"https://github.com/munisystem","followers_url":"https://api.github.com/users/munisystem/followers","following_url":"https://api.github.com/users/munisystem/following{/other_user}","gists_url":"https://api.github.com/users/munisystem/gists{/gist_id}","starred_url":"https://api.github.com/users/munisystem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/munisystem/subscriptions","organizations_url":"https://api.github.com/users/munisystem/orgs","repos_url":"https://api.github.com/users/munisystem/repos","events_url":"https://api.github.com/users/munisystem/events{/privacy}","received_events_url":"https://api.github.com/users/munisystem/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-25T03:02:08Z","updated_at":"2016-08-25T04:46:13Z","closed_at":null,"body":"## WHY\r\nTo reproduce, generated api server receive http request not including ``Accept`` header.\r\n\r\nsample code:\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"io/ioutil\"\r\n\t\"net/http\"\r\n)\r\n\r\nfunc main() {\r\n\turl := \"http://localhost:8080/api/users\"\r\n\treq, _ := http.NewRequest(\r\n\t\t\"GET\",\r\n\t\turl,\r\n\t\tnil,\r\n\t)\r\n\tclient := new(http.Client)\r\n\tresp, _ := client.Do(req)\r\n\tdefer resp.Body.Close()\r\n\tb, _ := ioutil.ReadAll(resp.Body)\r\n\tfmt.Printf(\"Response Body: %v\", string(b))\r\n}\r\n```\r\napi server logs:\r\n```\r\n2016/08/25 11:39:34 [Recovery] panic recovered:\r\nGET /api/users HTTP/1.1\r\nHost: localhost:3000\r\nAccept-Encoding: gzip\r\nUser-Agent: Go-http-client/1.1\r\n\r\n\r\nruntime error: index out of range\r\n/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:443 (0x402ce99)\r\n\tgopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz))\r\n/usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:27 (0x402b325)\r\n\tpanicindex: panic(indexError)\r\n/Users/muni/.go/src/github.com/wantedly/apig/_example/version/version.go:12 (0x43cb5e7)\r\n\tNew: header := c.Request.Header[\"Accept\"][0]\r\n/Users/muni/.go/src/github.com/wantedly/apig/_example/controllers/user.go:16 (0x42d6b83)\r\n\tGetUsers: ver, err := version.New(c)\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/context.go:97 (0x40755da)\r\n\t(*Context).Next: c.handlers[c.index](c)\r\n/Users/muni/.go/src/github.com/wantedly/apig/_example/middleware/set_db.go:12 (0x41072bb)\r\n\tSetDBtoContext.func1: c.Next()\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/context.go:97 (0x40755da)\r\n\t(*Context).Next: c.handlers[c.index](c)\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/recovery.go:45 (0x4087ef1)\r\n\tRecoveryWithWriter.func1: c.Next()\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/context.go:97 (0x40755da)\r\n\t(*Context).Next: c.handlers[c.index](c)\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/logger.go:63 (0x408718a)\r\n\tLoggerWithWriter.func1: c.Next()\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/context.go:97 (0x40755da)\r\n\t(*Context).Next: c.handlers[c.index](c)\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/gin.go:284 (0x407c432)\r\n\t(*Engine).handleHTTPRequest: context.Next()\r\n/Users/muni/.go/src/github.com/gin-gonic/gin/gin.go:265 (0x407c067)\r\n\t(*Engine).ServeHTTP: engine.handleHTTPRequest(c)\r\n/usr/local/Cellar/go/1.6.2/libexec/src/net/http/server.go:2081 (0x41e3d8e)\r\n\tserverHandler.ServeHTTP: handler.ServeHTTP(rw, req)\r\n/usr/local/Cellar/go/1.6.2/libexec/src/net/http/server.go:1472 (0x41e063e)\r\n\t(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)\r\n/usr/local/Cellar/go/1.6.2/libexec/src/runtime/asm_amd64.s:1998 (0x405cf41)\r\n\tgoexit: BYTE\t$0x90\t// NOP\r\n\r\n[GIN] 2016/08/25 - 11:39:34 | 500 |      1.4057ms | ::1 |   GET     /api/users\r\n```\r\n\r\n## WHAT\r\nIf http request not including ``Accept`` header, c.Request.Header[\"Accept\"] is empty.\r\n(type: map[string][]string) \r\nref. https://github.com/wantedly/apig/blob/master/_example/version/version.go#L12\r\n\r\nI think we should check map length and return that gist using response body.\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/wantedly/apig/issues/comments/242279997","html_url":"https://github.com/wantedly/apig/issues/85#issuecomment-242279997","issue_url":"https://api.github.com/repos/wantedly/apig/issues/85","id":242279997,"user":{"login":"shimastripe","id":15936908,"avatar_url":"https://avatars.githubusercontent.com/u/15936908?v=3","gravatar_id":"","url":"https://api.github.com/users/shimastripe","html_url":"https://github.com/shimastripe","followers_url":"https://api.github.com/users/shimastripe/followers","following_url":"https://api.github.com/users/shimastripe/following{/other_user}","gists_url":"https://api.github.com/users/shimastripe/gists{/gist_id}","starred_url":"https://api.github.com/users/shimastripe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shimastripe/subscriptions","organizations_url":"https://api.github.com/users/shimastripe/orgs","repos_url":"https://api.github.com/users/shimastripe/repos","events_url":"https://api.github.com/users/shimastripe/events{/privacy}","received_events_url":"https://api.github.com/users/shimastripe/received_events","type":"User","site_admin":false},"created_at":"2016-08-25T04:46:13Z","updated_at":"2016-08-25T04:46:13Z","body":"`Accept` header has a role as specifying version in `apig`, so I agree with you.\r\n\r\nIf there is no other opinion, I make PR in this issue.\r\nSpecifically, returns error message."}}
{"actor":{"display_login":"shimastripe"}}