-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
52 lines (44 loc) · 905 Bytes
/
config.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
package errors
import (
"fmt"
"sync"
"time"
)
var _cfg *config
var _once = new(sync.Once)
func init() {
_once.Do(func() {
_cfg = &config{loc: time.Local, depth: 1, skip: 3, formatFn: DefaultFormatFn}
})
}
type config struct {
loc *time.Location
depth int
skip int
formatFn Format
}
func (c *config) SetTimeLocation(loc *time.Location) {
if loc == nil {
panic("errors set time location failed, loc is nil")
}
c.loc = loc
}
func (c *config) SetStack(depth int, skip int) {
if depth < 1 {
panic(fmt.Errorf("errors set stack failed, depth valued %d is invalid", depth))
}
if skip < 1 {
panic(fmt.Errorf("errors set stack failed, skip valued %d is invalid", skip))
}
c.depth = depth
c.skip = skip
}
func (c *config) SetFormatFunc(fn Format) {
if fn == nil {
panic("errors set format func failed")
}
c.formatFn = fn
}
func Configure() *config {
return _cfg
}