{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/28391","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/28391/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/28391/comments","events_url":"https://api.github.com/repos/golang/go/issues/28391/events","html_url":"https://github.com/golang/go/issues/28391","id":374041503,"node_id":"MDU6SXNzdWUzNzQwNDE1MDM=","number":28391,"title":"text/template: allow callers to override IsTrue","user":{"login":"bep","id":394382,"node_id":"MDQ6VXNlcjM5NDM4Mg==","avatar_url":"https://avatars1.githubusercontent.com/u/394382?v=4","gravatar_id":"","url":"https://api.github.com/users/bep","html_url":"https://github.com/bep","followers_url":"https://api.github.com/users/bep/followers","following_url":"https://api.github.com/users/bep/following{/other_user}","gists_url":"https://api.github.com/users/bep/gists{/gist_id}","starred_url":"https://api.github.com/users/bep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bep/subscriptions","organizations_url":"https://api.github.com/users/bep/orgs","repos_url":"https://api.github.com/users/bep/repos","events_url":"https://api.github.com/users/bep/events{/privacy}","received_events_url":"https://api.github.com/users/bep/received_events","type":"User","site_admin":false},"labels":[{"id":373540105,"node_id":"MDU6TGFiZWwzNzM1NDAxMDU=","url":"https://api.github.com/repos/golang/go/labels/FeatureRequest","name":"FeatureRequest","color":"bfd4f2","default":false},{"id":373402289,"node_id":"MDU6TGFiZWwzNzM0MDIyODk=","url":"https://api.github.com/repos/golang/go/labels/NeedsInvestigation","name":"NeedsInvestigation","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/65","html_url":"https://github.com/golang/go/milestone/65","labels_url":"https://api.github.com/repos/golang/go/milestones/65/labels","id":3072996,"node_id":"MDk6TWlsZXN0b25lMzA3Mjk5Ng==","number":65,"title":"Go1.12","description":"","creator":{"login":"rsc","id":104030,"node_id":"MDQ6VXNlcjEwNDAzMA==","avatar_url":"https://avatars1.githubusercontent.com/u/104030?v=4","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":707,"closed_issues":339,"state":"open","created_at":"2018-01-29T21:17:52Z","updated_at":"2018-10-25T19:14:07Z","due_on":"2019-01-31T08:00:00Z","closed_at":null},"comments":4,"created_at":"2018-10-25T16:57:02Z","updated_at":"2018-10-25T19:16:07Z","closed_at":null,"author_association":"NONE","body":"The `IsTrue`, which is used in templates to determine if `if` and `when` etc. conditionals should be invoked makes sense in most situations. Some examples:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"text/template\"\r\n\t\"time\"\r\n)\r\n\r\nfunc main() {\r\n\r\n\ttype s struct{}\r\n\r\n\tprintIsTrue(1)         // true\r\n\tprintIsTrue(0)         // false\r\n\tprintIsTrue(-1)        // true\r\n\tprintIsTrue(s{})       // true\r\n\tprintIsTrue(&s{})      // true\r\n\tprintIsTrue((*s)(nil)) // false\r\n\tprintIsTrue(nil)       // false\r\n\tprintIsTrue(\"\")        // false\r\n\tprintIsTrue(\"foo\")     // true\r\n\r\n\tprintIsTrue(time.Now())  // true\r\n\tprintIsTrue(time.Time{}) // true\r\n\r\n}\r\n\r\nfunc printIsTrue(in interface{}) {\r\n\tb, _ := template.IsTrue(in)\r\n\tfmt.Println(b)\r\n}\r\n```\r\n\r\nMy main challenge with the above is that `Struct values are always true`-- even the zero `time.Time` value above.\r\n\r\nIt would be useful if the above method could check some additional `truther` interface:\r\n\r\n```bash\r\ntype truther interface {\r\n\tIsTrue() bool\r\n}\r\n```\r\n\r\nIf the above is considered a breaking change, an alternative suggestion would be to make the `template.IsTrue` function settable.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/433172530","html_url":"https://github.com/golang/go/issues/28391#issuecomment-433172530","issue_url":"https://api.github.com/repos/golang/go/issues/28391","id":433172530,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzE3MjUzMA==","user":{"login":"bcmills","id":5200974,"node_id":"MDQ6VXNlcjUyMDA5NzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/5200974?v=4","gravatar_id":"","url":"https://api.github.com/users/bcmills","html_url":"https://github.com/bcmills","followers_url":"https://api.github.com/users/bcmills/followers","following_url":"https://api.github.com/users/bcmills/following{/other_user}","gists_url":"https://api.github.com/users/bcmills/gists{/gist_id}","starred_url":"https://api.github.com/users/bcmills/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcmills/subscriptions","organizations_url":"https://api.github.com/users/bcmills/orgs","repos_url":"https://api.github.com/users/bcmills/repos","events_url":"https://api.github.com/users/bcmills/events{/privacy}","received_events_url":"https://api.github.com/users/bcmills/received_events","type":"User","site_admin":false},"created_at":"2018-10-25T19:16:07Z","updated_at":"2018-10-25T19:16:07Z","author_association":"MEMBER","body":"Ok, over to @robpike and @mvdan to decide: should we allow user code to override the meaning of `IsTrue` for template conditionals?"}}
{"actor":{"display_login":"bcmills"}}