go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/utils/syncx/map.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package syncx
     5  
     6  import "sync"
     7  
     8  type Map[T any] struct {
     9  	sync.Map
    10  }
    11  
    12  func (r *Map[T]) Get(key string) (T, bool) {
    13  	res, ok := r.Map.Load(key)
    14  	if !ok {
    15  		var zero T
    16  		return zero, ok
    17  	}
    18  	return res.(T), true
    19  }
    20  
    21  func (r *Map[T]) Set(key string, value T) {
    22  	r.Map.Store(key, value)
    23  }