github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/shell/hintsummary/class.go (about) 1 package hintsummary 2 3 import ( 4 "fmt" 5 "sync" 6 ) 7 8 // HintSummary is a thread-safe map for storing the hint summary overrides 9 type HintSummary struct { 10 mutex sync.Mutex 11 m map[string]string 12 } 13 14 // New creates a new instance of the hint summary override structure 15 func New() *HintSummary { 16 hs := new(HintSummary) 17 hs.m = make(map[string]string) 18 return hs 19 } 20 21 // Get returns the hint summary override 22 func (hs *HintSummary) Get(exe string) string { 23 hs.mutex.Lock() 24 s := hs.m[exe] 25 hs.mutex.Unlock() 26 return s 27 } 28 29 // Set stores the hint summary override for a specific executable 30 func (hs *HintSummary) Set(exe, summary string) { 31 hs.mutex.Lock() 32 hs.m[exe] = summary 33 hs.mutex.Unlock() 34 } 35 36 // Delete removes a hint summary for a specific executable 37 func (hs *HintSummary) Delete(exe string) error { 38 hs.mutex.Lock() 39 if hs.m[exe] == "" { 40 hs.mutex.Unlock() 41 return fmt.Errorf("no summary set for '%s'", exe) 42 } 43 44 delete(hs.m, exe) 45 hs.mutex.Unlock() 46 return nil 47 } 48 49 // Dump returns a JSON-able structure of the stored hint summary overrides 50 func (hs *HintSummary) Dump() map[string]string { 51 hs.mutex.Lock() 52 m := hs.m 53 hs.mutex.Unlock() 54 return m 55 }