{"action":"created","issue":{"url":"https://api.github.com/repos/manyminds/api2go/issues/317","repository_url":"https://api.github.com/repos/manyminds/api2go","labels_url":"https://api.github.com/repos/manyminds/api2go/issues/317/labels{/name}","comments_url":"https://api.github.com/repos/manyminds/api2go/issues/317/comments","events_url":"https://api.github.com/repos/manyminds/api2go/issues/317/events","html_url":"https://github.com/manyminds/api2go/issues/317","id":345465398,"node_id":"MDU6SXNzdWUzNDU0NjUzOTg=","number":317,"title":"Accessing gin Context from api2go resource handler","user":{"login":"dataBaseError","id":1715213,"node_id":"MDQ6VXNlcjE3MTUyMTM=","avatar_url":"https://avatars1.githubusercontent.com/u/1715213?v=4","gravatar_id":"","url":"https://api.github.com/users/dataBaseError","html_url":"https://github.com/dataBaseError","followers_url":"https://api.github.com/users/dataBaseError/followers","following_url":"https://api.github.com/users/dataBaseError/following{/other_user}","gists_url":"https://api.github.com/users/dataBaseError/gists{/gist_id}","starred_url":"https://api.github.com/users/dataBaseError/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dataBaseError/subscriptions","organizations_url":"https://api.github.com/users/dataBaseError/orgs","repos_url":"https://api.github.com/users/dataBaseError/repos","events_url":"https://api.github.com/users/dataBaseError/events{/privacy}","received_events_url":"https://api.github.com/users/dataBaseError/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-28T17:31:00Z","updated_at":"2018-07-31T12:01:38Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nIs there anyway to copy the context from a routing framework? Specifically the gin framework has [Context](https://godoc.org/github.com/gin-gonic/gin#Context) which you can [get](https://godoc.org/github.com/gin-gonic/gin#Context.Get) or [set](https://godoc.org/github.com/gin-gonic/gin#Context.Set) Keys. While api2go supports [Context](https://godoc.org/github.com/manyminds/api2go#APIContext), context set in Gin does not transfer to api2go.\r\n\r\nIs there existing way to support the context store in gin to be transferred to the api2go's context?\r\n\r\nAn example of this would be using gin middleware login which sets a Key `userID` on login. \r\n\r\nmain.go\r\n```go\r\n// ...\r\nr := gin.Default()\r\napi := api2go.NewAPIWithRouting(\r\n  \"api\",\r\n  api2go.NewStaticResolver(\"/\"),\r\n  routing.Gin(r),\r\n)\r\n\r\n// If login is successful will set `userID`.\r\nr.Use(login_handler.AuthMiddleware.MiddlewareFunc())\r\n\r\nr.Get(\"/test\", func(c *gin.Context) {\r\n\tuserId, ok := c.Get(\"userID\")\r\n\t// Value will be present\r\n\tfmt.Println(\"User \", userId, \" ok \", ok)\r\n}\r\n\r\n// ...\r\napi.AddResource(model.User{}, userResource)\r\n// ...\r\n```\r\n\r\nuser_resource.go\r\n```go\r\nfunc (s *UserResource) FindAll(r api2go.Request) (api2go.Responder, error) {\r\n\tv, ok := r.Context.Get(\"userID\")\r\n\t// Value will not be present\r\n\tfmt.Println(\"Account ID \", v, \" ok \", ok)\r\n\r\n\t// ...\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/manyminds/api2go/issues/comments/409195345","html_url":"https://github.com/manyminds/api2go/issues/317#issuecomment-409195345","issue_url":"https://api.github.com/repos/manyminds/api2go/issues/317","id":409195345,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTE5NTM0NQ==","user":{"login":"sharpner","id":574362,"node_id":"MDQ6VXNlcjU3NDM2Mg==","avatar_url":"https://avatars0.githubusercontent.com/u/574362?v=4","gravatar_id":"","url":"https://api.github.com/users/sharpner","html_url":"https://github.com/sharpner","followers_url":"https://api.github.com/users/sharpner/followers","following_url":"https://api.github.com/users/sharpner/following{/other_user}","gists_url":"https://api.github.com/users/sharpner/gists{/gist_id}","starred_url":"https://api.github.com/users/sharpner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharpner/subscriptions","organizations_url":"https://api.github.com/users/sharpner/orgs","repos_url":"https://api.github.com/users/sharpner/repos","events_url":"https://api.github.com/users/sharpner/events{/privacy}","received_events_url":"https://api.github.com/users/sharpner/received_events","type":"User","site_admin":false},"created_at":"2018-07-31T12:01:38Z","updated_at":"2018-07-31T12:01:38Z","author_association":"MEMBER","body":"Hello! Unfortunately there is no builtin method. But since our context is an implementation of an interface, in theory it should be possible to write a wrapper for the gin context which implements this interface: https://github.com/manyminds/api2go/blob/master/context.go#L12\r\nand replace the context with https://github.com/manyminds/api2go/blob/master/api_public.go#L37\r\n\r\nI hope it helps, and if it does, maybe you can let us know how it turned out :)"}}
{"actor":{"display_login":"sharpner"}}