-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconfig.go
More file actions
44 lines (38 loc) · 902 Bytes
/
config.go
File metadata and controls
44 lines (38 loc) · 902 Bytes
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
package errors
import (
"sync"
)
// Config represents the configuration options.
type Config struct {
StackDepth int // StackDepth specifies the depth of the function call stack trace. Default value is 10.
ErrorConnectionFlag string // ErrorConnectionFlag specifies the error connection flag string. Default value is "\nCaused by: ".
}
var (
cfg = defaultCfg
defaultCfg = &Config{
StackDepth: 10,
ErrorConnectionFlag: "\nCaused by: ",
}
rw sync.RWMutex
)
// SetCfg sets the global configuration instance.
func SetCfg(c *Config) {
if c == nil {
return
}
rw.Lock()
defer rw.Unlock()
cfg = c
}
// GetCfg retrieves the global configuration instance.
func GetCfg() *Config {
rw.RLock()
defer rw.RUnlock()
return cfg
}
// ResetCfg resets the global configuration to its default value.
func ResetCfg() {
rw.Lock()
defer rw.Unlock()
cfg = defaultCfg
}