google / gmail-oauth2-tools

Tools and sample code for authenticating to Gmail with OAuth2
Apache License 2.0
405 stars 211 forks source link

Use the XDG config directory by default #67

Closed favonia closed 8 months ago

favonia commented 8 months ago

Completely close #20.

Tagging @jasonkarns in case they have anything to say.

junyer commented 8 months ago

Done in commit 578a11a744c37bd19c1c1b8d96061276dbf6f7f0.

favonia commented 8 months ago

@junyer Thanks for your quick response. Out of curiosity, is there a reason to use sync.Once instead of a simple global variable (and init)?

junyer commented 8 months ago

sync.OnceValue() became available as of Go 1.21 only three months ago, admittedly, but it feels neater than setting a global variable via an init() function.

favonia commented 8 months ago

@junyer I checked the sync package and felt the overhead is quite large---there are mutexes to deal with multithreading and complicated control flows to optimize stack traces. None of these features are useful here. Personally I would suggest using simple boolean values, but I guess it does not hurt much and you are the maintainer. 😅

junyer commented 8 months ago

It isn't a hot code path, so what's happening under the hood doesn't hurt at all. It matters more to have clearer, simpler code: the use of sync.OnceValue() concisely signals that isXDG is a func() bool whose return value is memoised.