{"action":"created","issue":{"url":"https://api.github.com/repos/fatih/structs/issues/64","repository_url":"https://api.github.com/repos/fatih/structs","labels_url":"https://api.github.com/repos/fatih/structs/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/fatih/structs/issues/64/comments","events_url":"https://api.github.com/repos/fatih/structs/issues/64/events","html_url":"https://github.com/fatih/structs/pull/64","id":162042970,"number":64,"title":"Value tag","user":{"login":"webguerilla","id":278620,"avatar_url":"https://avatars.githubusercontent.com/u/278620?v=3","gravatar_id":"","url":"https://api.github.com/users/webguerilla","html_url":"https://github.com/webguerilla","followers_url":"https://api.github.com/users/webguerilla/followers","following_url":"https://api.github.com/users/webguerilla/following{/other_user}","gists_url":"https://api.github.com/users/webguerilla/gists{/gist_id}","starred_url":"https://api.github.com/users/webguerilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webguerilla/subscriptions","organizations_url":"https://api.github.com/users/webguerilla/orgs","repos_url":"https://api.github.com/users/webguerilla/repos","events_url":"https://api.github.com/users/webguerilla/events{/privacy}","received_events_url":"https://api.github.com/users/webguerilla/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-23T23:05:44Z","updated_at":"2016-06-24T22:11:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/fatih/structs/pulls/64","html_url":"https://github.com/fatih/structs/pull/64","diff_url":"https://github.com/fatih/structs/pull/64.diff","patch_url":"https://github.com/fatih/structs/pull/64.patch"},"body":"Hi Fatih,\r\n\r\nI use the structs package for creating a flat map which contains the arguments I need for a named query. See the function https://godoc.org/github.com/jmoiron/sqlx#DB.NamedExec\r\n\r\nHowever I run into issues with for example my NullTime type. My NullTime type is similar to the NullX types in the sql package of the standard library. See for example https://golang.org/pkg/database/sql/#NullBool\r\n\r\nI have something like this:\r\n\r\n```\r\ntype Record struct {\r\n    LastStartAt NullTime\r\n}\r\n\r\ntype NullTime struct {\r\n    Time time.Time\r\n    Valid bool\r\n}\r\n```\r\n\r\nIf I create a map from the Record, I would like to get an entry \"LastStartAt\" with the time.Time value and not a map[string]interface{}.\r\n\r\nI saw no way to get this result with the current functionality of the package, so I have implemented support for a \"value\" tag similar to the already implemented \"string\" tag.\r\n\r\nIf the \"value\" tag is set and the child struct implements the Valuer interface, the return value of the Valuex() function is set in the final map.\r\n\r\nSo I end up with something like the following and get the map I need. \r\n\r\n```\r\ntype Record struct {\r\n    LastStartAt NullTime `structs:\",value\"`\r\n}\r\n\r\ntype NullTime struct {\r\n    Time time.Time\r\n    Valid bool\r\n}\r\n\r\nfunc (nt NullTime) Valuex() interface{} {\r\n    return nt.Time\r\n}\r\n```\r\n\r\nWhat do you think about this? Is it something you like to add to the package? If so, I could implement a test and write some documentation.\r\n\r\nAnd if you like it, have you a suggestion for the function name? I'm not very happy with Valuex(), but Value() could not be used because it would result in a conflict if the sql/driver.Valuer interface of the standard library is also implemented by a type.\r\n\r\nBest regards,\r\nMarco"},"comment":{"url":"https://api.github.com/repos/fatih/structs/issues/comments/228474855","html_url":"https://github.com/fatih/structs/pull/64#issuecomment-228474855","issue_url":"https://api.github.com/repos/fatih/structs/issues/64","id":228474855,"user":{"login":"fatih","id":438920,"avatar_url":"https://avatars.githubusercontent.com/u/438920?v=3","gravatar_id":"","url":"https://api.github.com/users/fatih","html_url":"https://github.com/fatih","followers_url":"https://api.github.com/users/fatih/followers","following_url":"https://api.github.com/users/fatih/following{/other_user}","gists_url":"https://api.github.com/users/fatih/gists{/gist_id}","starred_url":"https://api.github.com/users/fatih/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatih/subscriptions","organizations_url":"https://api.github.com/users/fatih/orgs","repos_url":"https://api.github.com/users/fatih/repos","events_url":"https://api.github.com/users/fatih/events{/privacy}","received_events_url":"https://api.github.com/users/fatih/received_events","type":"User","site_admin":false},"created_at":"2016-06-24T22:11:32Z","updated_at":"2016-06-24T22:11:32Z","body":"> The keys have to match the names of the named placeholders. In this map I need the key LastStartAt with the value of time.Time. I could set this key manually, but I like to prevent manual post processing for each type...\r\n\r\nAlright, this is indeed a custom logic you want to include in this package. My suggestion would not help  you as it would add a different type. You don't want the `NullTime` to be stored, insted you want `NullTime.Time`\r\n\r\nI'm ok for this PR now, but we need to fix and add a couple of things:\r\n\r\n1. We need a test to cover this new feature\r\n2. The `Valuer` interface needs a doc comment\r\n3. I think `Valuex` is not a good method name. Maybe `StructValue()` or something else would be better. Also we need to document this in the `Map` doc comment as well\r\n\r\n"}}
{"actor":{"display_login":"fatih"}}