From e9f8fbcdf4d7b204018714aff5b4c2fab7228b66 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 2 Jun 2019 12:15:03 +0100 Subject: [PATCH] cert: use os.Hostname for the OU, and add the long form user name The output of the hostname command on Windows is probably UTF-16, but instead of figuring out its edge cases, switch to the syscall on every platform. Fixes #96 Closes #142 --- cert.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cert.go b/cert.go index 6482cde..ff62c0a 100644 --- a/cert.go +++ b/cert.go @@ -34,12 +34,16 @@ import ( var userAndHostname string func init() { - u, _ := user.Current() - if u != nil { + u, err := user.Current() + if err == nil { userAndHostname = u.Username + "@" } - hostname, _ := os.Hostname() - userAndHostname += hostname + if h, err := os.Hostname(); err == nil { + userAndHostname += h + } + if err == nil && u.Name != "" && u.Name != u.Username { + userAndHostname += " (" + u.Name + ")" + } } func (m *mkcert) makeCert(hosts []string) {