github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/os/base.go (about) 1 // Copyright 2024 Canonical Ltd. 2 // Licensed under the LGPLv3, see LICENCE file for details. 3 4 package os 5 6 import ( 7 "sync" 8 9 "github.com/juju/errors" 10 11 corebase "github.com/juju/juju/core/base" 12 ) 13 14 var ( 15 // HostBase returns the base of the machine the current process is 16 // running on (overrideable var for testing) 17 HostBase func() (corebase.Base, error) = hostBase 18 19 baseOnce sync.Once 20 21 // These are filled in by the first call to hostBase 22 base corebase.Base 23 baseErr error 24 ) 25 26 func hostBase() (corebase.Base, error) { 27 var err error 28 baseOnce.Do(func() { 29 base, err = readBase() 30 if err != nil { 31 baseErr = errors.Annotate(err, "cannot determine host base") 32 } 33 }) 34 return base, baseErr 35 }