TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Defaults – Simple default values in go structs

2 点作者 ilozinski超过 9 年前

1 comment

nvader超过 9 年前
Very interesting.<p>I see what might be a problem, however: determining the difference between a zero-value in a struct that was supplied intentionally, or one that was left unspecified.<p>To clarify what I mean, in the example on that page the following line doesn&#x27;t produce the right answer:<p><pre><code> p := defaults.NewWithDefaults(Person{ConvictedFelon: false}).(Person) </code></pre> Of course, you could perform the assignment after the defaults have been initialized, but then you&#x27;re giving up the optional struct initialization that Go provides. I&#x27;ll have to think about how you could solve this. In the meanwhile, I&#x27;ll open an issue on Github.
评论 #10961086 未加载