File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: Copyright The Lima Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ package registry
5
+
6
+ import (
7
+ "sync"
8
+
9
+ "github.com/lima-vm/lima/pkg/driver"
10
+ )
11
+
12
+ type Registry struct {
13
+ drivers map [string ]driver.Driver
14
+ mu sync.RWMutex
15
+ }
16
+
17
+ func NewRegistry () * Registry {
18
+ return & Registry {
19
+ drivers : make (map [string ]driver.Driver ),
20
+ }
21
+ }
22
+
23
+ func (r * Registry ) Register (driver driver.Driver ) {
24
+ r .mu .Lock ()
25
+ defer r .mu .Unlock ()
26
+
27
+ name := driver .Name ()
28
+ if _ , exists := r .drivers [name ]; exists {
29
+ return
30
+ }
31
+
32
+ r .drivers [name ] = driver
33
+ }
34
+
35
+ func (r * Registry ) Get (name string ) (driver.Driver , bool ) {
36
+ r .mu .RLock ()
37
+ defer r .mu .RUnlock ()
38
+
39
+ driver , exists := r .drivers [name ]
40
+ return driver , exists
41
+ }
42
+
43
+ var DefaultRegistry * Registry
44
+
45
+ func Register (driver driver.Driver ) {
46
+ if DefaultRegistry != nil {
47
+ DefaultRegistry .Register (driver )
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments