From: David Heuschmann Date: Wed, 19 Sep 2018 15:00:09 +0000 (+0200) Subject: os/user: note in doc that user.Current is being cached X-Git-Tag: go1.12beta1~1015 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eff3de0e63a905fa29715d63393860dbab92294f;p=gostls13.git os/user: note in doc that user.Current is being cached user.Current caches the current user after its first call, so changes to the uid after the first call will not affect its result. As this might be unexpected, it should be mentioned in the docs. Fixes #27659 Change-Id: I8b3323d55441d9a79bc9534c6490884d8561889b Reviewed-on: https://go-review.googlesource.com/136315 Reviewed-by: Ian Lance Taylor --- diff --git a/src/os/user/lookup.go b/src/os/user/lookup.go index 2243a25788..b36b7c01c0 100644 --- a/src/os/user/lookup.go +++ b/src/os/user/lookup.go @@ -7,6 +7,10 @@ package user import "sync" // Current returns the current user. +// +// The first call will cache the current user information. +// Subsequent calls will return the cached value and will not reflect +// changes to the current user. func Current() (*User, error) { cache.Do(func() { cache.u, cache.err = current() }) if cache.err != nil {