Skip to content

Commit

Permalink
dir optimize
Browse files Browse the repository at this point in the history
Signed-off-by: kl7sn <mex7.0828@gmail.com>
  • Loading branch information
kl7sn committed Jul 18, 2023
1 parent 70eab8a commit d744136
Show file tree
Hide file tree
Showing 46 changed files with 1,270 additions and 50 deletions.
10 changes: 10 additions & 0 deletions l/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/gotomicro/cetus/l

go 1.20

require go.uber.org/zap v1.24.0

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

import (
"go.uber.org/zap"
)

var (
I = zap.Int
I64 = zap.Int64
I32 = zap.Int32
F64 = zap.Float64
S = zap.String
B = zap.Bool
E = zap.Error
A = zap.Any
)
3 changes: 0 additions & 3 deletions preempt/go.mod

This file was deleted.

31 changes: 30 additions & 1 deletion kutils/math.go → x/cast.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
package kutils
package x

import (
"bytes"
"encoding/binary"
"math"
"strconv"

"github.com/gotomicro/ego/core/elog"
"go.uber.org/zap"
)

func S2I64(str string) int64 {
i, err := strconv.ParseInt(str, 10, 64)
if err != nil {
elog.Warn("S2I64 fail", zap.Error(err))
return 0
}
return i
}

type Int interface {
~int8 | ~int16 | ~int32 | ~int64 | ~int
}

type Uint interface {
~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uint
}

func I2S[T Int](i T) string {
return strconv.FormatInt(int64(i), 10)
}

func UI2S[T Uint](i T) string {
return strconv.FormatUint(uint64(i), 10)
}

// Float64ToByte Float64转byte
func Float64ToByte(float float64) []byte {
bits := math.Float64bits(float)
Expand Down
77 changes: 77 additions & 0 deletions x/cast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package x

import (
"log"
"testing"

"github.com/stretchr/testify/assert"
)

func TestS2I64(t *testing.T) {
cases := []struct {
in string
exp int64
}{
{"0", 0},
{"999", 999},
{"-999", -999},
}
for _, c := range cases {
res := S2I64(c.in)
log.Printf("%+v\n"+"res--------------->", res)
assert.Equal(t, c.exp, res)
}
}

func TestI2S(t *testing.T) {
type cs[T Int] struct {
in T
exp string
}
c1 := cs[int]{0, "0"}
res := I2S(c1.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c1.exp, res)

c2 := cs[int8]{9, "9"}
res = I2S(c2.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c2.exp, res)

c3 := cs[int32]{999, "999"}
res = I2S(c3.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c3.exp, res)

type MyI32 int32
c4 := cs[MyI32]{999, "999"}
res = I2S(c4.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c4.exp, res)

c5 := cs[int16]{9999, "9999"}
res = I2S(c5.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c5.exp, res)
}

func TestUI2S(t *testing.T) {
type cs[T Uint] struct {
in T
exp string
}
c1 := cs[uint8]{0, "0"}
res := UI2S(c1.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c1.exp, res)

c2 := cs[uint32]{9, "9"}
res = UI2S(c2.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c2.exp, res)

c3 := cs[uint64]{999, "999"}
res = UI2S(c3.in)
log.Printf("res--------------->"+"%+v\n", res)
assert.Equal(t, c3.exp, res)
}
2 changes: 1 addition & 1 deletion kutils/float.go → x/float.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kutils
package x

import (
"fmt"
Expand Down
25 changes: 25 additions & 0 deletions x/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module github.com/gotomicro/cetus/x

go 1.20

require (
github.com/gotomicro/ego v1.1.12
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.24.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gotomicro/logrotate v0.0.0-20211108034117-46d53eedc960 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
google.golang.org/grpc v1.46.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d744136

Please sign in to comment.