Skip to content

Commit d744136

Browse files
committed
dir optimize
Signed-off-by: kl7sn <mex7.0828@gmail.com>
1 parent 70eab8a commit d744136

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1270
-50
lines changed

l/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/gotomicro/cetus/l
2+
3+
go 1.20
4+
5+
require go.uber.org/zap v1.24.0
6+
7+
require (
8+
go.uber.org/atomic v1.7.0 // indirect
9+
go.uber.org/multierr v1.6.0 // indirect
10+
)

l/go.sum

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
6+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
10+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
11+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
12+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
13+
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
14+
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
15+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
16+
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
17+
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
18+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

l/zap.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package l
2+
3+
import (
4+
"go.uber.org/zap"
5+
)
6+
7+
var (
8+
I = zap.Int
9+
I64 = zap.Int64
10+
I32 = zap.Int32
11+
F64 = zap.Float64
12+
S = zap.String
13+
B = zap.Bool
14+
E = zap.Error
15+
A = zap.Any
16+
)

preempt/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

kutils/math.go renamed to x/cast.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1-
package kutils
1+
package x
22

33
import (
44
"bytes"
55
"encoding/binary"
66
"math"
7+
"strconv"
8+
9+
"github.com/gotomicro/ego/core/elog"
10+
"go.uber.org/zap"
711
)
812

13+
func S2I64(str string) int64 {
14+
i, err := strconv.ParseInt(str, 10, 64)
15+
if err != nil {
16+
elog.Warn("S2I64 fail", zap.Error(err))
17+
return 0
18+
}
19+
return i
20+
}
21+
22+
type Int interface {
23+
~int8 | ~int16 | ~int32 | ~int64 | ~int
24+
}
25+
26+
type Uint interface {
27+
~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uint
28+
}
29+
30+
func I2S[T Int](i T) string {
31+
return strconv.FormatInt(int64(i), 10)
32+
}
33+
34+
func UI2S[T Uint](i T) string {
35+
return strconv.FormatUint(uint64(i), 10)
36+
}
37+
938
// Float64ToByte Float64转byte
1039
func Float64ToByte(float float64) []byte {
1140
bits := math.Float64bits(float)

x/cast_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package x
2+
3+
import (
4+
"log"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestS2I64(t *testing.T) {
11+
cases := []struct {
12+
in string
13+
exp int64
14+
}{
15+
{"0", 0},
16+
{"999", 999},
17+
{"-999", -999},
18+
}
19+
for _, c := range cases {
20+
res := S2I64(c.in)
21+
log.Printf("%+v\n"+"res--------------->", res)
22+
assert.Equal(t, c.exp, res)
23+
}
24+
}
25+
26+
func TestI2S(t *testing.T) {
27+
type cs[T Int] struct {
28+
in T
29+
exp string
30+
}
31+
c1 := cs[int]{0, "0"}
32+
res := I2S(c1.in)
33+
log.Printf("res--------------->"+"%+v\n", res)
34+
assert.Equal(t, c1.exp, res)
35+
36+
c2 := cs[int8]{9, "9"}
37+
res = I2S(c2.in)
38+
log.Printf("res--------------->"+"%+v\n", res)
39+
assert.Equal(t, c2.exp, res)
40+
41+
c3 := cs[int32]{999, "999"}
42+
res = I2S(c3.in)
43+
log.Printf("res--------------->"+"%+v\n", res)
44+
assert.Equal(t, c3.exp, res)
45+
46+
type MyI32 int32
47+
c4 := cs[MyI32]{999, "999"}
48+
res = I2S(c4.in)
49+
log.Printf("res--------------->"+"%+v\n", res)
50+
assert.Equal(t, c4.exp, res)
51+
52+
c5 := cs[int16]{9999, "9999"}
53+
res = I2S(c5.in)
54+
log.Printf("res--------------->"+"%+v\n", res)
55+
assert.Equal(t, c5.exp, res)
56+
}
57+
58+
func TestUI2S(t *testing.T) {
59+
type cs[T Uint] struct {
60+
in T
61+
exp string
62+
}
63+
c1 := cs[uint8]{0, "0"}
64+
res := UI2S(c1.in)
65+
log.Printf("res--------------->"+"%+v\n", res)
66+
assert.Equal(t, c1.exp, res)
67+
68+
c2 := cs[uint32]{9, "9"}
69+
res = UI2S(c2.in)
70+
log.Printf("res--------------->"+"%+v\n", res)
71+
assert.Equal(t, c2.exp, res)
72+
73+
c3 := cs[uint64]{999, "999"}
74+
res = UI2S(c3.in)
75+
log.Printf("res--------------->"+"%+v\n", res)
76+
assert.Equal(t, c3.exp, res)
77+
}

kutils/float.go renamed to x/float.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kutils
1+
package x
22

33
import (
44
"fmt"

x/go.mod

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module github.com/gotomicro/cetus/x
2+
3+
go 1.20
4+
5+
require (
6+
github.com/gotomicro/ego v1.1.12
7+
github.com/stretchr/testify v1.8.4
8+
go.uber.org/zap v1.24.0
9+
)
10+
11+
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
13+
github.com/go-logr/logr v1.2.3 // indirect
14+
github.com/go-logr/stdr v1.2.2 // indirect
15+
github.com/gotomicro/logrotate v0.0.0-20211108034117-46d53eedc960 // indirect
16+
github.com/mitchellh/mapstructure v1.5.0 // indirect
17+
github.com/pmezard/go-difflib v1.0.0 // indirect
18+
github.com/spf13/cast v1.4.1 // indirect
19+
go.opentelemetry.io/otel v1.7.0 // indirect
20+
go.opentelemetry.io/otel/trace v1.7.0 // indirect
21+
go.uber.org/atomic v1.7.0 // indirect
22+
go.uber.org/multierr v1.6.0 // indirect
23+
google.golang.org/grpc v1.46.0 // indirect
24+
gopkg.in/yaml.v3 v3.0.1 // indirect
25+
)

0 commit comments

Comments
 (0)