Skip to content

Commit

Permalink
简单升级依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyile committed Feb 10, 2025
1 parent 1fbcbd8 commit 6365aa9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 75 deletions.
51 changes: 20 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
*.a
*.so
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.pyc
*.log
*.exe~
*.dll
*.out
*.key
_test
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
*.cert
*.exe~

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
.Trash-*
.DS_Store
go.work.sum
main.out.bin
*gitignore*secrets*
*gitignore*outputs*
ehthumbs.db
Thumbs.db
.gitkeep
.vscode/
*.dylib
vendor/
.idea/
*.err
*.swp
_obj
tmp/
bin/
tags
*.DB
*.db
*.o
*~

# env file
.env
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ go 1.22.6
require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0
github.com/yyle88/zaplog v0.0.17
github.com/yyle88/zaplog v0.0.19
go.uber.org/zap v1.27.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/yyle88/mutexmap v1.0.9 // indirect
github.com/yyle88/mutexmap v1.0.10 // indirect
go.uber.org/multierr v1.11.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yyle88/mutexmap v1.0.9 h1:g1nfNmsReU/AgcGkLgPEKrBeMThJJBrJuvU7i3DOVC0=
github.com/yyle88/mutexmap v1.0.9/go.mod h1:QUYDuARLPlGj414kHewQ5tt8jkDxQXoai8H3C4Gg+yc=
github.com/yyle88/zaplog v0.0.17 h1:2exjnXROfkNRvcKZDAFUM2KDpca1n2OKrEH73pTvrX0=
github.com/yyle88/zaplog v0.0.17/go.mod h1:SJvxdHW7zWu1r+K66oBPBWljiGnDjCV8le3SzQnJpBw=
github.com/yyle88/mutexmap v1.0.10 h1:PIsx9KTdK6h1yH5NzBrPl21RrZ/XsE4IbgulMlhJzZE=
github.com/yyle88/mutexmap v1.0.10/go.mod h1:QUYDuARLPlGj414kHewQ5tt8jkDxQXoai8H3C4Gg+yc=
github.com/yyle88/zaplog v0.0.19 h1:O4g7EO+uks7DkXbBXAje0LRvrBbkPuMD4gphuXw9jAo=
github.com/yyle88/zaplog v0.0.19/go.mod h1:jN9/2IXYlpHOgoIyOTid1EPlUyGBWzFjr0dX9YKLkC0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
Expand Down
46 changes: 23 additions & 23 deletions must.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
// True 期望值为 true。如果值为 false,则触发 panic。
func True(v bool) {
if !v {
zaplog.ZAPS.P1.LOG.Panic("expect TRUE while got FALSE", zap.Bool("v", v))
zaplog.ZAPS.Skip1.LOG.Panic("expect TRUE while got FALSE", zap.Bool("v", v))
}
}

// Done expects no error. Panics if the provided error is non-nil.
// Done 期望没有错误。如果提供的错误不为 nil,则触发 panic。
func Done(err error) {
if err != nil {
zaplog.ZAPS.P1.LOG.Panic("NO ERROR BUG", zap.Error(err))
zaplog.ZAPS.Skip1.LOG.Panic("NO ERROR BUG", zap.Error(err))
}
}

// Must expects no error. Panics if the provided error is non-nil.
// Must 期望没有错误。如果提供的错误不为 nil,则触发 panic。
func Must(err error) {
if err != nil {
zaplog.ZAPS.P1.LOG.Panic("ERROR", zap.Error(err))
zaplog.ZAPS.Skip1.LOG.Panic("ERROR", zap.Error(err))
}
}

Expand All @@ -35,7 +35,7 @@ func Must(err error) {
func Nice[V comparable](a V) V {
var b V // zero value
if a == b {
zaplog.ZAPS.P1.LOG.Panic("A IS ZERO VALUE", zap.Any("a", a))
zaplog.ZAPS.Skip1.LOG.Panic("A IS ZERO VALUE", zap.Any("a", a))
}
return a
}
Expand All @@ -45,7 +45,7 @@ func Nice[V comparable](a V) V {
func Zero[V comparable](a V) {
var b V // zero value
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A IS NOT ZERO VALUE", zap.Any("a", a))
zaplog.ZAPS.Skip1.LOG.Panic("A IS NOT ZERO VALUE", zap.Any("a", a))
}
}

Expand All @@ -54,63 +54,63 @@ func Zero[V comparable](a V) {
func None[V comparable](a V) {
var b V // zero value
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A IS NOT NONE VALUE", zap.Any("a", a))
zaplog.ZAPS.Skip1.LOG.Panic("A IS NOT NONE VALUE", zap.Any("a", a))
}
}

// Null expects the value to be nil. Panics if the value is non-nil.
// Null 期望值为 nil。如果值不为 nil,则触发 panic。
func Null[T any](v *T) {
if v != nil {
zaplog.ZAPS.P1.LOG.Panic("SHOULD BE NULL BUT IS FULL")
zaplog.ZAPS.Skip1.LOG.Panic("SHOULD BE NULL BUT IS FULL")
}
}

// Full expects the value to be non-nil. Panics if the value is nil.
// Full 期望值为非 nil。如果值为 nil,则触发 panic。
func Full[T any](v *T) {
if v == nil {
zaplog.ZAPS.P1.LOG.Panic("SHOULD BE FULL BUT IS NULL")
zaplog.ZAPS.Skip1.LOG.Panic("SHOULD BE FULL BUT IS NULL")
}
}

// Equal expects the values to be equal. Panics if they are not equal.
// Equal 期望值相等。如果值不相等,则触发 panic。
func Equal[V comparable](a, b V) {
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A AND B ARE NOT EQUAL", zap.Any("a", a), zap.Any("b", b))
zaplog.ZAPS.Skip1.LOG.Panic("A AND B ARE NOT EQUAL", zap.Any("a", a), zap.Any("b", b))
}
}

// Equals expects the values to be equal. Panics if they are not equal.
// Equals 期望值相等。如果值不相等,则触发 panic。
func Equals[V comparable](a, b V) {
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A AND B ARE NOT EQUALS", zap.Any("a", a), zap.Any("b", b))
zaplog.ZAPS.Skip1.LOG.Panic("A AND B ARE NOT EQUALS", zap.Any("a", a), zap.Any("b", b))
}
}

// Same expects the values to be same. Panics if they are not same.
// Same 期望值相等。如果值不相等,则触发 panic。
func Same[V comparable](a, b V) {
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A AND B ARE NOT SAME", zap.Any("a", a), zap.Any("b", b))
zaplog.ZAPS.Skip1.LOG.Panic("A AND B ARE NOT SAME", zap.Any("a", a), zap.Any("b", b))
}
}

// Is expects equality, not the logic of errors.Is, but the logic of Equals. Panics if the values are not equal.
// Is 期望相等,不是 errors.Is 的逻辑,而是 Equals 的逻辑。如果值不相等,则触发 panic。
func Is[V comparable](a, b V) {
if a != b {
zaplog.ZAPS.P1.LOG.Panic("A AND B ARE NOT EQUALS", zap.Any("a", a), zap.Any("b", b))
zaplog.ZAPS.Skip1.LOG.Panic("A AND B ARE NOT EQUALS", zap.Any("a", a), zap.Any("b", b))
}
}

// Ise expects the errors to be equal, similar to the behavior of errors.Is. Panics if they are not equal.
// Ise 期望错误相等,类似于 errors.Is 的行为。如果错误不相等,则触发 panic。
func Ise(err, target error) {
if !errors.Is(err, target) {
zaplog.ZAPS.P1.LOG.Panic("ERROR IS NOT SAME", zap.Error(err), zap.Error(target))
zaplog.ZAPS.Skip1.LOG.Panic("ERROR IS NOT SAME", zap.Error(err), zap.Error(target))
}
}

Expand All @@ -119,7 +119,7 @@ func Ise(err, target error) {
func Ok[V comparable](a V) {
var b V // zero value
if a == b {
zaplog.ZAPS.P1.LOG.Panic("A IS ZERO VALUE NOT OK", zap.Any("a", a))
zaplog.ZAPS.Skip1.LOG.Panic("A IS ZERO VALUE NOT OK", zap.Any("a", a))
}
}

Expand All @@ -128,55 +128,55 @@ func Ok[V comparable](a V) {
func OK[V comparable](a V) {
var b V // zero value
if a == b {
zaplog.ZAPS.P1.LOG.Panic("A IS ZERO VALUE NOT OK", zap.Any("a", a))
zaplog.ZAPS.Skip1.LOG.Panic("A IS ZERO VALUE NOT OK", zap.Any("a", a))
}
}

// TRUE expects the value to be true. Panics if the value is false.
// TRUE 期望值为 true。如果值为 false,则触发 panic。
func TRUE(v bool) {
if !v {
zaplog.ZAPS.P1.LOG.Panic("expect TRUE while got FALSE", zap.Bool("v", v))
zaplog.ZAPS.Skip1.LOG.Panic("expect TRUE while got FALSE", zap.Bool("v", v))
}
}

// FALSE expects the value to be false. Panics if the value is true.
// FALSE 期望值为 false。如果值为 true,则触发 panic。
func FALSE(v bool) {
if v {
zaplog.ZAPS.P1.LOG.Panic("expect FALSE while got TRUE", zap.Bool("v", v))
zaplog.ZAPS.Skip1.LOG.Panic("expect FALSE while got TRUE", zap.Bool("v", v))
}
}

// False expects the value to be false. Panics if the value is true.
// False 期望值为 false。如果值为 true,则触发 panic。
func False(v bool) {
if v {
zaplog.ZAPS.P1.LOG.Panic("expect FALSE while got TRUE", zap.Bool("v", v))
zaplog.ZAPS.Skip1.LOG.Panic("expect FALSE while got TRUE", zap.Bool("v", v))
}
}

// Have checks that the slice is not empty/none. Panics if the slice is empty/none.
// Have 检查切片是否为空。如果切片为空,则触发 panic。
func Have[T any](a []T) {
if len(a) == 0 {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH > 0 while got an empty/none slice")
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH > 0 while got an empty/none slice")
}
}

// Length expects the slice to have length n. Panics if the length is not n.
// Length 期望切片的长度为 n。如果长度不是 n,则触发 panic。
func Length[T any](a []T, n int) {
if len(a) != n {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
}
}

// Len is an abbreviation of Length, serving the same purpose. Panics if the length is not n.
// Len 是 Length 的缩写,功能相同。如果长度不是 n,则触发 panic。
func Len[T any](a []T, n int) {
if len(a) != n {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
}
}

Expand All @@ -188,7 +188,7 @@ func In[T comparable](v T, a []T) {
return
}
}
zaplog.ZAPS.P1.LOG.Panic("expect value in slice while not in", zap.Any("v", v), zap.Int("len", len(a)))
zaplog.ZAPS.Skip1.LOG.Panic("expect value in slice while not in", zap.Any("v", v), zap.Int("len", len(a)))
}

// Contains checks if the slice contains the value. Panics if the value is not found.
Expand All @@ -199,5 +199,5 @@ func Contains[T comparable](a []T, v T) {
return
}
}
zaplog.ZAPS.P1.LOG.Panic("expect slice contains value while not contains", zap.Int("len", len(a)), zap.Any("v", v))
zaplog.ZAPS.Skip1.LOG.Panic("expect slice contains value while not contains", zap.Int("len", len(a)), zap.Any("v", v))
}
14 changes: 7 additions & 7 deletions mustmap/must_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
// Equals 比较两个 map 是否相等,如果不相等,则触发 panic。
func Equals[K, V comparable](a, b map[K]V) {
if !maps.Equal(a, b) {
zaplog.ZAPS.P1.LOG.Panic("expect map equals while not equals", zap.Int("len_a", len(a)), zap.Int("len_b", len(b)))
zaplog.ZAPS.Skip1.LOG.Panic("expect map equals while not equals", zap.Int("len_a", len(a)), zap.Int("len_b", len(b)))
}
}

// Have checks if a map is non-empty. If it is empty, it panics.
// Have 检查一个 map 是否非空,如果为空,则触发 panic。
func Have[K comparable, V any](a map[K]V) {
if len(a) == 0 {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH > 0 while got an none map")
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH > 0 while got an none map")
}
}

// Nice checks if a map is non-empty and returns it. If it is empty, it panics.
// Nice 检查一个 map 是否非空并返回它,如果为空,则触发 panic。
func Nice[K comparable, V any](a map[K]V) map[K]V {
if len(a) == 0 {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH > 0 while got an none map")
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH > 0 while got an none map")
}
return a
}
Expand All @@ -36,23 +36,23 @@ func Nice[K comparable, V any](a map[K]V) map[K]V {
// None 确保 map 内容为空,若有元素则 panic。
func None[K comparable, V any](a map[K]V) {
if len(a) != 0 {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH = 0 while contains elements")
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH = 0 while contains elements")
}
}

// Length checks if the length of a map is equal to n. If not, it panics.
// Length 检查一个 map 的长度是否等于 n,如果不等,则触发 panic。
func Length[K comparable, V any](a map[K]V, n int) {
if len(a) != n {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
}
}

// Len checks if the length of a map is equal to n. If not, it panics.
// Len 是 Length 的简写版本,检查一个 map 的长度是否等于 n,如果不等,则触发 panic。
func Len[K comparable, V any](a map[K]V, n int) {
if len(a) != n {
zaplog.ZAPS.P1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
zaplog.ZAPS.Skip1.LOG.Panic("expect LENGTH = n while not equals", zap.Int("len", len(a)), zap.Int("n", n))
}
}

Expand All @@ -61,7 +61,7 @@ func Len[K comparable, V any](a map[K]V, n int) {
func Get[K, V comparable](a map[K]V, key K) V {
value, exists := a[key]
if !exists {
zaplog.ZAPS.P1.LOG.Panic("expect KEY to EXIST in map", zap.Any("key", key))
zaplog.ZAPS.Skip1.LOG.Panic("expect KEY to EXIST in map", zap.Any("key", key))
}
return value
}
Loading

0 comments on commit 6365aa9

Please sign in to comment.