Documentation
¶
Overview ¶
Package shared holds constants and small helpers shared across packages that would otherwise need to import the full client package.
Index ¶
- Constants
- Variables
- type Map
- func (sm *Map[K, V]) All() iter.Seq2[K, V]
- func (sm *Map[K, V]) Clear()
- func (sm *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (sm *Map[K, V]) CompareAndSwap(key K, o V, n V) (swapped bool)
- func (sm *Map[K, V]) Delete(key K)
- func (sm *Map[K, V]) Keys() []K
- func (sm *Map[K, V]) Len() int
- func (sm *Map[K, V]) Load(key K) (V, bool)
- func (sm *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (sm *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (sm *Map[K, V]) Range(fn func(key K, value V) bool)
- func (sm *Map[K, V]) Store(key K, value V)
- func (sm *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)
- func (sm *Map[K, V]) Values() []V
- type SyncMap
Examples ¶
Constants ¶
const ( HealthStatusUnknown = "unknown" HealthStatusStarting = "starting" HealthStatusHealthy = "healthy" HealthStatusUnhealthy = "unhealthy" HealthStatusStopped = "stopped" HealthKeyPrefix = "user.healthcheck." // HealthStatusKey is the instance config key used to store health status. HealthStatusKey = HealthKeyPrefix + "status" // HealthEnabledKey when "true" opts the instance in, and is the only thing // ic-healthd consults. On a project it means the same one level up. HealthEnabledKey = HealthKeyPrefix + "enabled" // HealthStoppedKey when "true" means healthchecking is stopped. HealthStoppedKey = HealthKeyPrefix + "stopped" // HealthIgnoreKey opts an instance out of health checking entirely. HealthIgnoreKey = HealthKeyPrefix + "ignore" // HealthScopeKey names the daemon watching a project. Missing means neither. HealthScopeKey = HealthKeyPrefix + "scope" )
Health check status constants written to HealthConfigKey by ic-healthd.
const ( HealthScopeProject = "project" HealthScopeGlobal = "global" )
Values of HealthScopeKey.
const ( Incus72Extension = "oci_network_config" Incus73Extension = "instance_port_forward" )
Those define extensions that came with a specific release.
Variables ¶
var RestartPolicies = []string{"always", "on-failure", "unless-stopped"}
RestartPolicies are the restart values worth tracking even without a test command.
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v1.2.0
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map provides a thread-safe generic map built on top of sync.Map.
The zero value is ready for use. A Map must not be copied after first use.
Example (All) ¶
ExampleMap_all demonstrates how to iterate over the map.
var m Map[string, string]
m.Store("LOC", "USA")
m.Store("LANG", "EN")
// Collect keys for consistent output order
var keys []string
for key := range m.All() {
keys = append(keys, key)
}
sort.Strings(keys)
for _, k := range keys {
v, _ := m.Load(k)
fmt.Printf("%s: %s\n", k, v)
}
Output: LANG: EN LOC: USA
Example (Usage) ¶
ExampleMap_usage demonstrates basic usage of Map.
var m Map[string, int]
m.Store("apple", 10)
m.Store("banana", 20)
if val, ok := m.Load("apple"); ok {
fmt.Printf("apple: %d\n", val)
}
m.Delete("banana")
Output: apple: 10
func (*Map[K, V]) All ¶ added in v1.2.0
All returns an iterator over the keys and values in the map. All does not necessarily observe a consistent snapshot when the map is modified concurrently.
func (*Map[K, V]) CompareAndDelete ¶ added in v1.2.0
CompareAndDelete deletes the entry for key if its value is equal to old. It panics if old is not comparable, matching sync.Map.
func (*Map[K, V]) CompareAndSwap ¶ added in v1.2.0
CompareAndSwap swaps the old and new values for key if the value stored in the map is equal to old. It panics if old is not comparable, matching sync.Map.
func (*Map[K, V]) Keys ¶ added in v1.2.0
func (sm *Map[K, V]) Keys() []K
Keys returns the keys encountered during one Range call. It does not return a consistent snapshot when the map is modified concurrently.
func (*Map[K, V]) Len ¶ added in v1.2.0
Len returns the number of keys encountered during one Range call in O(N) time. It does not return a consistent snapshot when the map is modified concurrently.
func (*Map[K, V]) Load ¶ added in v1.2.0
Load gets a value by key, returning the value and whether it was found.
func (*Map[K, V]) LoadAndDelete ¶ added in v1.2.0
LoadAndDelete gets an existing value and deletes it, returning the value and whether it was loaded.
func (*Map[K, V]) LoadOrStore ¶ added in v1.2.0
LoadOrStore gets an existing value or stores a new one, returning the actual value and whether it was loaded.
func (*Map[K, V]) Range ¶ added in v1.2.0
Range calls fn sequentially for each key-value pair. Returning false stops the iteration. Range does not necessarily observe a consistent snapshot when the map is modified concurrently.
func (*Map[K, V]) Store ¶ added in v1.2.0
func (sm *Map[K, V]) Store(key K, value V)
Store sets a key-value pair.
type SyncMap ¶ added in v1.2.0
type SyncMap[K comparable, V any] = Map[K, V]
SyncMap is an alias for Map retained for compatibility.
func NewSyncMap ¶ added in v1.2.0
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
NewSyncMap creates a new thread-safe generic map.