Skip to content

Commit f1c4748

Browse files
committed
v1.5.74
1 parent 1942e21 commit f1c4748

File tree

11 files changed

+110
-97
lines changed

11 files changed

+110
-97
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/go-pay/gopay
22

33
go 1.16
44

5-
require golang.org/x/crypto v0.0.0-20220214200702-86341886e292
5+
require golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
2-
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
1+
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
2+
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
33
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
44
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
55
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

pkg/aes/aes_gcm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto/cipher"
66
"fmt"
77

8-
"github.com/go-pay/gopher/util"
8+
"github.com/go-pay/gopay/pkg/util"
99
)
1010

1111
// AES-GCM 加密数据

pkg/aes/aes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/base64"
55
"testing"
66

7-
"github.com/go-pay/gopher/xlog"
7+
"github.com/go-pay/gopay/pkg/xlog"
88
)
99

1010
var (

pkg/xlog/debug_logger.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"runtime"
8-
"strconv"
9-
"strings"
107
"sync"
118
)
129

@@ -19,26 +16,26 @@ func (i *DebugLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
1916
i.once.Do(func() {
2017
i.init()
2118
})
22-
if col != nil {
19+
if Level >= DebugLevel {
20+
if col != nil {
21+
if format != nil {
22+
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
23+
return
24+
}
25+
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
26+
return
27+
}
2328
if format != nil {
24-
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
29+
i.logger.Output(3, fmt.Sprintf(*format, v...))
2530
return
2631
}
27-
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
28-
return
29-
}
30-
if format != nil {
31-
i.logger.Output(3, fmt.Sprintf(*format, v...))
32-
return
32+
i.logger.Output(3, fmt.Sprintln(v...))
3333
}
34-
i.logger.Output(3, fmt.Sprintln(v...))
3534
}
3635

3736
func (i *DebugLogger) init() {
38-
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
39-
if intNum >= 14 {
40-
i.logger = log.New(os.Stdout, "[DEBUG] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
41-
return
37+
if Level == 0 {
38+
Level = DebugLevel
4239
}
43-
i.logger = log.New(os.Stdout, "[DEBUG] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
40+
i.logger = log.New(os.Stdout, "[DEBUG] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
4441
}

pkg/xlog/error_logger.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"runtime"
8-
"strconv"
9-
"strings"
107
"sync"
118
)
129

@@ -19,26 +16,26 @@ func (e *ErrorLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
1916
e.once.Do(func() {
2017
e.init()
2118
})
22-
if col != nil {
19+
if Level >= ErrorLevel {
20+
if col != nil {
21+
if format != nil {
22+
e.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
23+
return
24+
}
25+
e.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
26+
return
27+
}
2328
if format != nil {
24-
e.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
29+
e.logger.Output(3, fmt.Sprintf(*format, v...))
2530
return
2631
}
27-
e.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
28-
return
29-
}
30-
if format != nil {
31-
e.logger.Output(3, fmt.Sprintf(*format, v...))
32-
return
32+
e.logger.Output(3, fmt.Sprintln(v...))
3333
}
34-
e.logger.Output(3, fmt.Sprintln(v...))
3534
}
3635

3736
func (e *ErrorLogger) init() {
38-
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
39-
if intNum >= 14 {
40-
e.logger = log.New(os.Stdout, "[ERROR] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
41-
return
37+
if Level == 0 {
38+
Level = DebugLevel
4239
}
43-
e.logger = log.New(os.Stdout, "[ERROR] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
40+
e.logger = log.New(os.Stdout, "[ERROR] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
4441
}

pkg/xlog/info_logger.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"runtime"
8-
"strconv"
9-
"strings"
107
"sync"
118
)
129

@@ -19,26 +16,26 @@ func (i *InfoLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
1916
i.once.Do(func() {
2017
i.init()
2118
})
22-
if col != nil {
19+
if Level >= InfoLevel {
20+
if col != nil {
21+
if format != nil {
22+
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
23+
return
24+
}
25+
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
26+
return
27+
}
2328
if format != nil {
24-
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
29+
i.logger.Output(3, fmt.Sprintf(*format, v...))
2530
return
2631
}
27-
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
28-
return
29-
}
30-
if format != nil {
31-
i.logger.Output(3, fmt.Sprintf(*format, v...))
32-
return
32+
i.logger.Output(3, fmt.Sprintln(v...))
3333
}
34-
i.logger.Output(3, fmt.Sprintln(v...))
3534
}
3635

3736
func (i *InfoLogger) init() {
38-
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
39-
if intNum >= 14 {
40-
i.logger = log.New(os.Stdout, "[INFO] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
41-
return
37+
if Level == 0 {
38+
Level = DebugLevel
4239
}
43-
i.logger = log.New(os.Stdout, "[INFO] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
40+
i.logger = log.New(os.Stdout, "[INFO] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
4441
}

pkg/xlog/log.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
package xlog
22

3+
const (
4+
ErrorLevel LogLevel = iota + 1
5+
WarnLevel
6+
InfoLevel
7+
DebugLevel
8+
)
9+
10+
type LogLevel int
11+
312
var (
413
debugLog XLogger = &DebugLogger{}
514
infoLog XLogger = &InfoLogger{}
615
warnLog XLogger = &WarnLogger{}
716
errLog XLogger = &ErrorLogger{}
17+
18+
Level LogLevel
819
)
920

1021
type XLogger interface {
@@ -42,19 +53,3 @@ func Error(args ...interface{}) {
4253
func Errorf(format string, args ...interface{}) {
4354
errLog.LogOut(nil, &format, args...)
4455
}
45-
46-
func SetDebugLog(logger XLogger) {
47-
debugLog = logger
48-
}
49-
50-
func SetInfoLog(logger XLogger) {
51-
infoLog = logger
52-
}
53-
54-
func SetWarnLog(logger XLogger) {
55-
warnLog = logger
56-
}
57-
58-
func SetErrLog(logger XLogger) {
59-
errLog = logger
60-
}

pkg/xlog/log_test.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
11
package xlog
22

33
import (
4+
"context"
45
"testing"
6+
7+
"github.com/go-pay/gopay/pkg/errgroup"
58
)
69

710
func TestLog(t *testing.T) {
11+
var eg errgroup.Group
812

913
// default log
10-
Info(White, "白色 info", Reset, WhiteBright, "高亮 info", Reset, "恢复默认颜色", WhiteDelLine, "删除线", Reset, WhiteUnderLine, "下划线", Reset, WhiteBevel, "斜体 info", Reset, WhiteBg, "背景", Reset)
11-
Debug(Cyan, "青色 debug", Reset, CyanBright, "高亮 debug", Reset, "恢复默认颜色", CyanDelLine, "删除线", Reset, CyanUnderLine, "下划线", Reset, CyanBevel, "斜体 debug", Reset, CyanBg, "背景", Reset)
12-
Warn(Yellow, "黄色 warning", Reset, YellowBright, "高亮 warning", Reset, "恢复默认颜色", YellowDelLine, "删除线", Reset, YellowUnderLine, "下划线", Reset, YellowBevel, "斜体 warning", Reset, YellowBg, "背景", Reset)
13-
Error(Red, "红色 error", Reset, RedBright, "高亮 error", Reset, "恢复默认颜色", RedDelLine, "删除线", Reset, RedUnderLine, "下划线", Reset, RedBevel, "斜体 error", Reset, RedBg, "背景", Reset)
14+
eg.Go(func(ctx context.Context) error {
15+
Info(White, "白色 info", Reset, WhiteBright, "高亮 info", Reset, "恢复默认颜色", WhiteDelLine, "删除线", Reset, WhiteUnderLine, "下划线", Reset, WhiteBevel, "斜体 info", Reset, WhiteBg, "背景", Reset)
16+
return nil
17+
})
18+
eg.Go(func(ctx context.Context) error {
19+
Debug(Cyan, "青色 debug", Reset, CyanBright, "高亮 debug", Reset, "恢复默认颜色", CyanDelLine, "删除线", Reset, CyanUnderLine, "下划线", Reset, CyanBevel, "斜体 debug", Reset, CyanBg, "背景", Reset)
20+
return nil
21+
})
22+
eg.Go(func(ctx context.Context) error {
23+
Warn(Yellow, "黄色 warning", Reset, YellowBright, "高亮 warning", Reset, "恢复默认颜色", YellowDelLine, "删除线", Reset, YellowUnderLine, "下划线", Reset, YellowBevel, "斜体 warning", Reset, YellowBg, "背景", Reset)
24+
return nil
25+
})
26+
eg.Go(func(ctx context.Context) error {
27+
Error(Red, "红色 error", Reset, RedBright, "高亮 error", Reset, "恢复默认颜色", RedDelLine, "删除线", Reset, RedUnderLine, "下划线", Reset, RedBevel, "斜体 error", Reset, RedBg, "背景", Reset)
28+
return nil
29+
})
1430

1531
// color log
16-
Color(White).Info("color log info")
17-
Color(Cyan).Debug("color log debug")
18-
Color(Yellow).Warn("color log warn")
19-
Color(Red).Error("color log error")
32+
eg.Go(func(ctx context.Context) error {
33+
Color(White).Info("color log info")
34+
return nil
35+
})
36+
eg.Go(func(ctx context.Context) error {
37+
Color(Cyan).Debug("color log debug")
38+
return nil
39+
})
40+
eg.Go(func(ctx context.Context) error {
41+
Color(Yellow).Warn("color log warn")
42+
return nil
43+
})
44+
eg.Go(func(ctx context.Context) error {
45+
Color(Red).Error("color log error")
46+
return nil
47+
})
48+
_ = eg.Wait()
2049
}

pkg/xlog/warn_logger.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"runtime"
8-
"strconv"
9-
"strings"
107
"sync"
118
)
129

@@ -19,26 +16,26 @@ func (i *WarnLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
1916
i.once.Do(func() {
2017
i.init()
2118
})
22-
if col != nil {
19+
if Level >= WarnLevel {
20+
if col != nil {
21+
if format != nil {
22+
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
23+
return
24+
}
25+
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
26+
return
27+
}
2328
if format != nil {
24-
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
29+
i.logger.Output(3, fmt.Sprintf(*format, v...))
2530
return
2631
}
27-
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
28-
return
29-
}
30-
if format != nil {
31-
i.logger.Output(3, fmt.Sprintf(*format, v...))
32-
return
32+
i.logger.Output(3, fmt.Sprintln(v...))
3333
}
34-
i.logger.Output(3, fmt.Sprintln(v...))
3534
}
3635

3736
func (i *WarnLogger) init() {
38-
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
39-
if intNum >= 14 {
40-
i.logger = log.New(os.Stdout, "[WARN] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
41-
return
37+
if Level == 0 {
38+
Level = DebugLevel
4239
}
43-
i.logger = log.New(os.Stdout, "[WARN] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
40+
i.logger = log.New(os.Stdout, "[WARN] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
4441
}

0 commit comments

Comments
 (0)