mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-21 20:52:19 +00:00
Use Once for CachedHostname
This commit is contained in:
parent
e6662e11c3
commit
5b160ea599
2 changed files with 8 additions and 12 deletions
|
|
@ -11,14 +11,10 @@ var _ = fmt.Print
|
|||
|
||||
var hostname string = "*"
|
||||
|
||||
func CachedHostname() string {
|
||||
if hostname == "*" {
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = h
|
||||
} else {
|
||||
hostname = ""
|
||||
}
|
||||
var Hostname = (&Once[string]{Run: func() string {
|
||||
h, err := os.Hostname()
|
||||
if err == nil {
|
||||
return h
|
||||
}
|
||||
return hostname
|
||||
}
|
||||
return ""
|
||||
}}).Get
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue