{"action":"created","issue":{"url":"https://api.github.com/repos/go-sql-driver/mysql/issues/306","labels_url":"https://api.github.com/repos/go-sql-driver/mysql/issues/306/labels{/name}","comments_url":"https://api.github.com/repos/go-sql-driver/mysql/issues/306/comments","events_url":"https://api.github.com/repos/go-sql-driver/mysql/issues/306/events","html_url":"https://github.com/go-sql-driver/mysql/issues/306","id":54667087,"number":306,"title":"How to pass a database connection as a parameter? What argument type should i use?","user":{"login":"nomad-software","id":1413497,"avatar_url":"https://avatars.githubusercontent.com/u/1413497?v=3","gravatar_id":"","url":"https://api.github.com/users/nomad-software","html_url":"https://github.com/nomad-software","followers_url":"https://api.github.com/users/nomad-software/followers","following_url":"https://api.github.com/users/nomad-software/following{/other_user}","gists_url":"https://api.github.com/users/nomad-software/gists{/gist_id}","starred_url":"https://api.github.com/users/nomad-software/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nomad-software/subscriptions","organizations_url":"https://api.github.com/users/nomad-software/orgs","repos_url":"https://api.github.com/users/nomad-software/repos","events_url":"https://api.github.com/users/nomad-software/events{/privacy}","received_events_url":"https://api.github.com/users/nomad-software/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-17T16:49:11Z","updated_at":"2015-01-17T16:57:12Z","closed_at":null,"body":"How to pass the database connection as a parameter?\r\n\r\nI currently have a function defined like this:\r\n\r\n```go\r\nfunc handleProtocols(connection driver.Conn, output http.ResponseWriter, request *http.Request) {\r\n\r\n\tswitch request.Method {\r\n\t\tcase \"GET\":\r\n\t\t\tio.WriteString(output, \"Protocols\\n\")\r\n\t\r\n\t\tdefault:\r\n\t\t\tio.WriteString(output, \"Mode not supported!\\n\")\r\n\t}\r\n}\r\n```\r\nand using it like this:\r\n```go\r\n\tconnection, err := sql.Open(\"mysql\", \"/database\")\r\n\r\n\thttp.HandleFunc(\"/protocols\", func (output http.ResponseWriter, request *http.Request) {\r\n\t\thandleProtocols(connection, output, request)\r\n\t})\r\n```\r\nTo which i get this error:\r\n\r\n```\r\n./restful.go:33: cannot use connection (type *sql.DB) as type driver.Conn in argument to handleProtocols:\r\n        *sql.DB does not implement driver.Conn (wrong type for Begin method)\r\n                have Begin() (*sql.Tx, error)\r\n                want Begin() (driver.Tx, error)\r\n```\r\nSo i'm currently forced to write the handler function like this to pass the connection:\r\n```go\r\nfunc handleProtocols(connection interface{}, output http.ResponseWriter, request *http.Request) {\r\n...\r\n```\r\nAm i missing something here?"},"comment":{"url":"https://api.github.com/repos/go-sql-driver/mysql/issues/comments/70374151","html_url":"https://github.com/go-sql-driver/mysql/issues/306#issuecomment-70374151","issue_url":"https://api.github.com/repos/go-sql-driver/mysql/issues/306","id":70374151,"user":{"login":"DisposaBlackSwan","id":8778270,"avatar_url":"https://avatars.githubusercontent.com/u/8778270?v=3","gravatar_id":"","url":"https://api.github.com/users/DisposaBlackSwan","html_url":"https://github.com/DisposaBlackSwan","followers_url":"https://api.github.com/users/DisposaBlackSwan/followers","following_url":"https://api.github.com/users/DisposaBlackSwan/following{/other_user}","gists_url":"https://api.github.com/users/DisposaBlackSwan/gists{/gist_id}","starred_url":"https://api.github.com/users/DisposaBlackSwan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DisposaBlackSwan/subscriptions","organizations_url":"https://api.github.com/users/DisposaBlackSwan/orgs","repos_url":"https://api.github.com/users/DisposaBlackSwan/repos","events_url":"https://api.github.com/users/DisposaBlackSwan/events{/privacy}","received_events_url":"https://api.github.com/users/DisposaBlackSwan/received_events","type":"User","site_admin":false},"created_at":"2015-01-17T16:57:12Z","updated_at":"2015-01-17T16:57:12Z","body":"The error says it all: `type *sql.DB` ... `func handleProtocols(connection *sql.DB` http://golang.org/pkg/database/sql/#Open"}}