Oct 1, 2022
Your first example has a few issues...
The first is that , contextually, the race doesn't matter. All callers are racing to assign the same value to v. It still looks bad, so you're right to want to fix it...
sync.Once might be more than you need, however. You could set the value of v in init() and then there will never be any issue.