forked from microsoftgraph/msgraph-sdk-go-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_mappings_registry.go
58 lines (49 loc) · 1.21 KB
/
error_mappings_registry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package msgraphgocore
import (
"errors"
abstractions "github.com/microsoft/kiota-abstractions-go"
"sync"
)
var lock = &sync.Mutex{}
type errorRegistry struct {
registry map[string]abstractions.ErrorMappings
}
var singleInstance *errorRegistry
// Create a global thread safe singleton for global values
func getInstance() *errorRegistry {
if singleInstance == nil {
lock.Lock()
defer lock.Unlock()
if singleInstance == nil {
singleInstance = &errorRegistry{
registry: make(map[string]abstractions.ErrorMappings),
}
}
}
return singleInstance
}
func RegisterError(key string, value abstractions.ErrorMappings) error {
single := getInstance()
_, found := single.registry[key]
if !found {
single.registry[key] = value
return nil
} else {
return errors.New("object Factory already register")
}
}
func DeRegisterError(key string) error {
single := getInstance()
_, found := single.registry[key]
if found {
delete(single.registry, key)
return nil
} else {
return errors.New("object Factory does not exist register")
}
}
func GetErrorFactoryFromRegistry(key string) (abstractions.ErrorMappings, bool) {
single := getInstance()
item, found := single.registry[key]
return item, found
}