Skip to content

Commit

Permalink
v1.5.74
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Mar 19, 2022
1 parent 1942e21 commit f1c4748
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 97 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/go-pay/gopay

go 1.16

require golang.org/x/crypto v0.0.0-20220214200702-86341886e292
require golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
2 changes: 1 addition & 1 deletion pkg/aes/aes_gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/cipher"
"fmt"

"github.com/go-pay/gopher/util"
"github.com/go-pay/gopay/pkg/util"
)

// AES-GCM 加密数据
Expand Down
2 changes: 1 addition & 1 deletion pkg/aes/aes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/base64"
"testing"

"github.com/go-pay/gopher/xlog"
"github.com/go-pay/gopay/pkg/xlog"
)

var (
Expand Down
31 changes: 14 additions & 17 deletions pkg/xlog/debug_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
)

Expand All @@ -19,26 +16,26 @@ func (i *DebugLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
i.once.Do(func() {
i.init()
})
if col != nil {
if Level >= DebugLevel {
if col != nil {
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
i.logger.Output(3, fmt.Sprintln(v...))
}
i.logger.Output(3, fmt.Sprintln(v...))
}

func (i *DebugLogger) init() {
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
if intNum >= 14 {
i.logger = log.New(os.Stdout, "[DEBUG] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
return
if Level == 0 {
Level = DebugLevel
}
i.logger = log.New(os.Stdout, "[DEBUG] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
i.logger = log.New(os.Stdout, "[DEBUG] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
}
31 changes: 14 additions & 17 deletions pkg/xlog/error_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
)

Expand All @@ -19,26 +16,26 @@ func (e *ErrorLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
e.once.Do(func() {
e.init()
})
if col != nil {
if Level >= ErrorLevel {
if col != nil {
if format != nil {
e.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
return
}
e.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
e.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
e.logger.Output(3, fmt.Sprintf(*format, v...))
return
}
e.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
e.logger.Output(3, fmt.Sprintf(*format, v...))
return
e.logger.Output(3, fmt.Sprintln(v...))
}
e.logger.Output(3, fmt.Sprintln(v...))
}

func (e *ErrorLogger) init() {
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
if intNum >= 14 {
e.logger = log.New(os.Stdout, "[ERROR] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
return
if Level == 0 {
Level = DebugLevel
}
e.logger = log.New(os.Stdout, "[ERROR] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
e.logger = log.New(os.Stdout, "[ERROR] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
}
31 changes: 14 additions & 17 deletions pkg/xlog/info_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
)

Expand All @@ -19,26 +16,26 @@ func (i *InfoLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
i.once.Do(func() {
i.init()
})
if col != nil {
if Level >= InfoLevel {
if col != nil {
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
i.logger.Output(3, fmt.Sprintln(v...))
}
i.logger.Output(3, fmt.Sprintln(v...))
}

func (i *InfoLogger) init() {
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
if intNum >= 14 {
i.logger = log.New(os.Stdout, "[INFO] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
return
if Level == 0 {
Level = DebugLevel
}
i.logger = log.New(os.Stdout, "[INFO] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
i.logger = log.New(os.Stdout, "[INFO] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
}
27 changes: 11 additions & 16 deletions pkg/xlog/log.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package xlog

const (
ErrorLevel LogLevel = iota + 1
WarnLevel
InfoLevel
DebugLevel
)

type LogLevel int

var (
debugLog XLogger = &DebugLogger{}
infoLog XLogger = &InfoLogger{}
warnLog XLogger = &WarnLogger{}
errLog XLogger = &ErrorLogger{}

Level LogLevel
)

type XLogger interface {
Expand Down Expand Up @@ -42,19 +53,3 @@ func Error(args ...interface{}) {
func Errorf(format string, args ...interface{}) {
errLog.LogOut(nil, &format, args...)
}

func SetDebugLog(logger XLogger) {
debugLog = logger
}

func SetInfoLog(logger XLogger) {
infoLog = logger
}

func SetWarnLog(logger XLogger) {
warnLog = logger
}

func SetErrLog(logger XLogger) {
errLog = logger
}
45 changes: 37 additions & 8 deletions pkg/xlog/log_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
package xlog

import (
"context"
"testing"

"github.com/go-pay/gopay/pkg/errgroup"
)

func TestLog(t *testing.T) {
var eg errgroup.Group

// default log
Info(White, "白色 info", Reset, WhiteBright, "高亮 info", Reset, "恢复默认颜色", WhiteDelLine, "删除线", Reset, WhiteUnderLine, "下划线", Reset, WhiteBevel, "斜体 info", Reset, WhiteBg, "背景", Reset)
Debug(Cyan, "青色 debug", Reset, CyanBright, "高亮 debug", Reset, "恢复默认颜色", CyanDelLine, "删除线", Reset, CyanUnderLine, "下划线", Reset, CyanBevel, "斜体 debug", Reset, CyanBg, "背景", Reset)
Warn(Yellow, "黄色 warning", Reset, YellowBright, "高亮 warning", Reset, "恢复默认颜色", YellowDelLine, "删除线", Reset, YellowUnderLine, "下划线", Reset, YellowBevel, "斜体 warning", Reset, YellowBg, "背景", Reset)
Error(Red, "红色 error", Reset, RedBright, "高亮 error", Reset, "恢复默认颜色", RedDelLine, "删除线", Reset, RedUnderLine, "下划线", Reset, RedBevel, "斜体 error", Reset, RedBg, "背景", Reset)
eg.Go(func(ctx context.Context) error {
Info(White, "白色 info", Reset, WhiteBright, "高亮 info", Reset, "恢复默认颜色", WhiteDelLine, "删除线", Reset, WhiteUnderLine, "下划线", Reset, WhiteBevel, "斜体 info", Reset, WhiteBg, "背景", Reset)
return nil
})
eg.Go(func(ctx context.Context) error {
Debug(Cyan, "青色 debug", Reset, CyanBright, "高亮 debug", Reset, "恢复默认颜色", CyanDelLine, "删除线", Reset, CyanUnderLine, "下划线", Reset, CyanBevel, "斜体 debug", Reset, CyanBg, "背景", Reset)
return nil
})
eg.Go(func(ctx context.Context) error {
Warn(Yellow, "黄色 warning", Reset, YellowBright, "高亮 warning", Reset, "恢复默认颜色", YellowDelLine, "删除线", Reset, YellowUnderLine, "下划线", Reset, YellowBevel, "斜体 warning", Reset, YellowBg, "背景", Reset)
return nil
})
eg.Go(func(ctx context.Context) error {
Error(Red, "红色 error", Reset, RedBright, "高亮 error", Reset, "恢复默认颜色", RedDelLine, "删除线", Reset, RedUnderLine, "下划线", Reset, RedBevel, "斜体 error", Reset, RedBg, "背景", Reset)
return nil
})

// color log
Color(White).Info("color log info")
Color(Cyan).Debug("color log debug")
Color(Yellow).Warn("color log warn")
Color(Red).Error("color log error")
eg.Go(func(ctx context.Context) error {
Color(White).Info("color log info")
return nil
})
eg.Go(func(ctx context.Context) error {
Color(Cyan).Debug("color log debug")
return nil
})
eg.Go(func(ctx context.Context) error {
Color(Yellow).Warn("color log warn")
return nil
})
eg.Go(func(ctx context.Context) error {
Color(Red).Error("color log error")
return nil
})
_ = eg.Wait()
}
31 changes: 14 additions & 17 deletions pkg/xlog/warn_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
"sync"
)

Expand All @@ -19,26 +16,26 @@ func (i *WarnLogger) LogOut(col *ColorType, format *string, v ...interface{}) {
i.once.Do(func() {
i.init()
})
if col != nil {
if Level >= WarnLevel {
if col != nil {
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, string(*col)+fmt.Sprintf(*format, v...)+string(Reset))
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
}
i.logger.Output(3, string(*col)+fmt.Sprintln(v...)+string(Reset))
return
}
if format != nil {
i.logger.Output(3, fmt.Sprintf(*format, v...))
return
i.logger.Output(3, fmt.Sprintln(v...))
}
i.logger.Output(3, fmt.Sprintln(v...))
}

func (i *WarnLogger) init() {
intNum, _ := strconv.Atoi(strings.Split(runtime.Version(), ".")[1])
if intNum >= 14 {
i.logger = log.New(os.Stdout, "[WARN] >> ", 64|log.Llongfile|log.Ldate|log.Lmicroseconds)
return
if Level == 0 {
Level = DebugLevel
}
i.logger = log.New(os.Stdout, "[WARN] ", log.Llongfile|log.Ldate|log.Lmicroseconds)
i.logger = log.New(os.Stdout, "[WARN] >> ", log.Lmsgprefix|log.Lshortfile|log.Ldate|log.Lmicroseconds)
}
1 change: 1 addition & 0 deletions release_note.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
版本号:Release 1.5.74
修改记录:
(1) gopay:一些小改动,util.GetRandomString() -> util.RandomString()
(2) gopay:升级 xlog

版本号:Release 1.5.73
修改记录:
Expand Down

0 comments on commit f1c4748

Please sign in to comment.