github.com/haraldrudell/parl@v0.4.176/pnet/interface-cacher.go (about) 1 /* 2 © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pnet 7 8 import "sync/atomic" 9 10 var networkInterfaceNameCache = NewInterfaceCache().Init() 11 var updateDisabled atomic.Bool 12 13 func UpdateNameCache() (err error) { 14 if !updateDisabled.Load() { 15 _, err = networkInterfaceNameCache.Update() 16 } 17 return 18 } 19 20 func CachedName(ifIndex IfIndex) (name string) { 21 return networkInterfaceNameCache.CachedNameNoUpdate(ifIndex) 22 } 23 24 func NameCache() (m map[IfIndex]string) { 25 return networkInterfaceNameCache.Map() 26 } 27 28 func SetTestMap(testMap map[IfIndex]string, disableUpdate bool) (oldMap map[IfIndex]string) { 29 updateDisabled.Store(disableUpdate) 30 return networkInterfaceNameCache.SetMap(testMap) 31 }