73a98393c6
Conflicts: vendor.mod Conflict because code.cloudfoundry.org/clock moved to a direct dependency in vendor.mod on master branch since342b44bf20
full diff:6341884e5f...b17f02f0a0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit64f9ea1cf5
) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
34 lines
717 B
Go
34 lines
717 B
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package klog
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func getUserName() string {
|
|
userNameOnce.Do(func() {
|
|
// On Windows, the Go 'user' package requires netapi32.dll.
|
|
// This affects Windows Nano Server:
|
|
// https://github.com/golang/go/issues/21867
|
|
// Fallback to using environment variables.
|
|
u := os.Getenv("USERNAME")
|
|
if len(u) == 0 {
|
|
return
|
|
}
|
|
// Sanitize the USERNAME since it may contain filepath separators.
|
|
u = strings.Replace(u, `\`, "_", -1)
|
|
|
|
// user.Current().Username normally produces something like 'USERDOMAIN\USERNAME'
|
|
d := os.Getenv("USERDOMAIN")
|
|
if len(d) != 0 {
|
|
userName = d + "_" + u
|
|
} else {
|
|
userName = u
|
|
}
|
|
})
|
|
|
|
return userName
|
|
}
|