Skip to content

Commit

Permalink
update: Use help instead of third-party libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kainonly committed Sep 23, 2023
1 parent d3badd4 commit ae31d83
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 56 deletions.
4 changes: 2 additions & 2 deletions csrf/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/common/utils"
"github.com/cloudwego/hertz/pkg/protocol"
"github.com/gookit/goutil/strutil"
"github.com/weplanx/go/help"
"net/http"
)

Expand Down Expand Up @@ -88,7 +88,7 @@ func SetDomain(v string) Option {
}

func (x *Csrf) SetToken(c *app.RequestContext) {
salt := strutil.MicroTimeHexID()
salt := help.Random(8)
c.SetCookie(x.SaltName, salt, 86400, "/", "", protocol.CookieSameSiteStrictMode, true, true)
c.SetCookie(x.CookieName, x.Tokenize(salt), 86400, "/", x.Domain, protocol.CookieSameSiteStrictMode, true, false)
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ require (
github.com/bytedance/gopkg v0.0.0-20230728082804-614d0af6619b
github.com/bytedance/sonic v1.10.1
github.com/cloudwego/hertz v0.6.8
github.com/go-faker/faker/v4 v4.1.1
github.com/go-faker/faker/v4 v4.2.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/gookit/goutil v0.6.12
github.com/nats-io/nats.go v1.29.0
github.com/nats-io/nkeys v0.4.4
github.com/redis/go-redis/v9 v9.1.0
github.com/google/uuid v1.3.1
github.com/nats-io/nats.go v1.30.0
github.com/nats-io/nkeys v0.4.5
github.com/redis/go-redis/v9 v9.2.0
github.com/stretchr/testify v1.8.4
go.mongodb.org/mongo-driver v1.12.1
golang.org/x/crypto v0.13.0
Expand All @@ -31,7 +31,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
Expand Down
36 changes: 16 additions & 20 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ github.com/andeya/ameda v1.5.3 h1:SvqnhQPZwwabS8HQTRGfJwWPl2w9ZIPInHAw9aE1Wlk=
github.com/andeya/ameda v1.5.3/go.mod h1:FQDHRe1I995v6GG+8aJ7UIUToEmbdTJn/U26NCPIgXQ=
github.com/andeya/goutil v1.0.1 h1:eiYwVyAnnK0dXU5FJsNjExkJW4exUGn/xefPt3k4eXg=
github.com/andeya/goutil v1.0.1/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7nhJDo=
github.com/bsm/ginkgo/v2 v2.9.5 h1:rtVBYPs3+TC5iLUVOis1B9tjLTup7Cj5IfzosKtvTJ0=
github.com/bsm/ginkgo/v2 v2.9.5/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM=
github.com/bytedance/go-tagexpr/v2 v2.9.9 h1:nawxXMVp7/Fba0lnDiZACj1hy0cMfqWg94OJN3KB7vQ=
github.com/bytedance/go-tagexpr/v2 v2.9.9/go.mod h1:UAyKh4ZRLBPGsyTRFZoPqTni1TlojMdOJXQnEIPCX84=
Expand Down Expand Up @@ -41,8 +41,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cu
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-faker/faker/v4 v4.1.1 h1:zkxj/JH/aezB4R6cTEMKU7qcVScGhlB3qRtF3D7K+rI=
github.com/go-faker/faker/v4 v4.1.1/go.mod h1:uuNc0PSRxF8nMgjGrrrU4Nw5cF30Jc6Kd0/FUTTYbhg=
github.com/go-faker/faker/v4 v4.2.0 h1:dGebOupKwssrODV51E0zbMrv5e2gO9VWSLNC1WDCpWg=
github.com/go-faker/faker/v4 v4.2.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -56,10 +56,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
github.com/gookit/goutil v0.6.12 h1:73vPUcTtVGXbhSzBOFcnSB1aJl7Jq9np3RAE50yIDZc=
github.com/gookit/goutil v0.6.12/go.mod h1:g6krlFib8xSe3G1h02IETowOtrUGpAmetT8IevDpvpM=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/henrylee2cn/ameda v1.4.8/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
Expand All @@ -68,8 +66,8 @@ github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/D
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
Expand All @@ -91,10 +89,10 @@ github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a h1:lem6QCvxR0Y28g
github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
github.com/nats-io/nats-server/v2 v2.8.2 h1:5m1VytMEbZx0YINvKY+X2gXdLNwP43uLXnFRwz8j8KE=
github.com/nats-io/nats-server/v2 v2.8.2/go.mod h1:vIdpKz3OG+DCg4q/xVPdXHoztEyKDWRtykQ4N7hd7C4=
github.com/nats-io/nats.go v1.29.0 h1:dSXZ+SZeGyTdHVYeXimeq12FsIpb9dM8CJ2IZFiHcyE=
github.com/nats-io/nats.go v1.29.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
github.com/nats-io/nats.go v1.30.0 h1:bj/rVsRCrFXxmm9mJiDhb74UKl2HhKpDwKRBtvCjZjc=
github.com/nats-io/nats.go v1.30.0/go.mod h1:dcfhUgmQNN4GJEfIb2f9R7Fow+gzBF4emzDHrVBd5qM=
github.com/nats-io/nkeys v0.4.5 h1:Zdz2BUlFm4fJlierwvGK+yl20IAKUm7eV6AAZXEhkPk=
github.com/nats-io/nkeys v0.4.5/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
Expand All @@ -103,8 +101,8 @@ github.com/nyaruka/phonenumbers v1.1.8/go.mod h1:DC7jZd321FqUe+qWSNcHi10tyIyGNXG
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
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/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY=
github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c=
github.com/redis/go-redis/v9 v9.2.0 h1:zwMdX0A4eVzse46YN18QhuDiM4uf3JmkOB4VZrdt5uI=
github.com/redis/go-redis/v9 v9.2.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
Expand Down Expand Up @@ -139,8 +137,6 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
Expand Down
10 changes: 5 additions & 5 deletions passlib/passlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

var (
DEFAULT_MEMORY_COST uint32 = 65536
DEFAULT_TIME_COST uint32 = 4
DEFAULT_THREADS uint8 = 1
DefaultMemoryCost uint32 = 65536
DefaultTimeCost uint32 = 4
DefaultThreads uint8 = 1
)

var (
Expand All @@ -29,10 +29,10 @@ func Hash(password string) (hash string, err error) {
return
}
key := argon2.IDKey([]byte(password), salt,
DEFAULT_TIME_COST, DEFAULT_MEMORY_COST, DEFAULT_THREADS, 32)
DefaultTimeCost, DefaultMemoryCost, DefaultThreads, 32)

return fmt.Sprintf(`$argon2id$v=%d$m=%d,t=%d,p=%d$%s$%s`,
argon2.Version, DEFAULT_MEMORY_COST, DEFAULT_TIME_COST, DEFAULT_THREADS,
argon2.Version, DefaultMemoryCost, DefaultTimeCost, DefaultThreads,
base64.RawStdEncoding.EncodeToString(salt),
base64.RawStdEncoding.EncodeToString(key),
), nil
Expand Down
4 changes: 2 additions & 2 deletions rest/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/utils"
"github.com/gookit/goutil/strutil"
"github.com/weplanx/go/help"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -617,7 +617,7 @@ func (x *Controller) Sort(ctx context.Context, c *app.RequestContext) {
// Transaction
// @router /transaction [POST]
func (x *Controller) Transaction(ctx context.Context, c *app.RequestContext) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
x.Service.Transaction(ctx, txn)
c.JSON(http.StatusCreated, utils.H{
"txn": txn,
Expand Down
29 changes: 14 additions & 15 deletions rest/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"fmt"
"github.com/bytedance/sonic"
"github.com/go-faker/faker/v4"
"github.com/gookit/goutil/arrutil"
"github.com/gookit/goutil/strutil"
"github.com/stretchr/testify/assert"
"github.com/weplanx/go/help"
"github.com/weplanx/go/passlib"
"github.com/weplanx/go/rest"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestCreateTransformBad(t *testing.T) {
}

func TestCreateTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("POST", "/users/create", M{
"data": M{
"name": "weplanx",
Expand Down Expand Up @@ -238,7 +237,7 @@ func TestBulkCreateTransformBad(t *testing.T) {
}

func TestBulkCreateTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("POST", "/roles/bulk_create", M{
"data": []M{
{
Expand Down Expand Up @@ -750,7 +749,7 @@ func TestUpdateTransformDataBad(t *testing.T) {
}

func TestUpdateTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("POST", "/roles/update", M{
"filter": M{
"key": "*",
Expand Down Expand Up @@ -955,7 +954,7 @@ func TestUpdateByIdTransformDataBad(t *testing.T) {
}

func TestUpdateByIdTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("PATCH", fmt.Sprintf(`/users/%s`, userId), M{
"data": M{
"$set": M{
Expand Down Expand Up @@ -1144,7 +1143,7 @@ func TestReplaceTransformBad(t *testing.T) {
}

func TestReplaceTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("PUT", fmt.Sprintf(`/users/%s`, userId), M{
"data": M{
"name": "kain",
Expand Down Expand Up @@ -1277,7 +1276,7 @@ func TestDeleteForbid(t *testing.T) {
}

func TestDeleteTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("DELETE", fmt.Sprintf(`/users/%s?txn=%s`, userId, txn), nil)
assert.NoError(t, err)
assert.Equal(t, 400, resp.StatusCode())
Expand Down Expand Up @@ -1364,7 +1363,7 @@ func TestBulkDeleteTransformBad(t *testing.T) {
}

func TestBulkDeleteTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
resp, err := R("POST", "/roles/bulk_delete", M{
"filter": M{
"key": "*",
Expand Down Expand Up @@ -1472,9 +1471,9 @@ func TestSortForbid(t *testing.T) {
}

func TestSortTxnNotExists(t *testing.T) {
txn := strutil.MicroTimeHexID()
txn := help.Uuid()
sources := orderIds[:5]
arrutil.Reverse[string](sources)
help.Reverse[string](sources)
resp, err := R("POST", "/orders/sort", M{
"data": M{
"key": "sort",
Expand All @@ -1488,7 +1487,7 @@ func TestSortTxnNotExists(t *testing.T) {

func TestSort(t *testing.T) {
sources := orderIds[:5]
arrutil.Reverse[string](sources)
help.Reverse[string](sources)
resp, err := R("POST", "/orders/sort", M{
"data": M{
"key": "sort",
Expand Down Expand Up @@ -1521,7 +1520,7 @@ func TestSortEvent(t *testing.T) {
ch := make(chan rest.PublishDto)
go MockSubscribe(t, ch)

arrutil.Reverse[string](projectIds)
help.Reverse[string](projectIds)
resp, err := R("POST", "/projects/sort", M{
"data": M{
"key": "sort",
Expand Down Expand Up @@ -1549,7 +1548,7 @@ func TestSortEvent(t *testing.T) {
func TestSortEventBad(t *testing.T) {
RemoveStream(t)

arrutil.Reverse[string](projectIds)
help.Reverse[string](projectIds)
resp, err := R("POST", "/projects/sort", M{
"data": M{
"key": "sort",
Expand Down Expand Up @@ -1973,7 +1972,7 @@ func TestCommitNotTxn(t *testing.T) {
assert.Equal(t, 400, resp1.StatusCode())

resp2, err := R("POST", "/commit", M{
"txn": strutil.MicroTimeHexID(),
"txn": help.Uuid(),
})
assert.NoError(t, err)
assert.Equal(t, 400, resp2.StatusCode())
Expand Down
4 changes: 2 additions & 2 deletions sessions/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"
"github.com/bytedance/sonic"
"github.com/gookit/goutil/strutil"
"github.com/stretchr/testify/assert"
"github.com/weplanx/go/help"
"go.mongodb.org/mongo-driver/bson/primitive"
"testing"
)
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestClearEmpty(t *testing.T) {
func TestRemove(t *testing.T) {
ctx := context.TODO()
uid := primitive.NewObjectID().Hex()
status := service.Set(ctx, uid, strutil.MicroTimeHexID())
status := service.Set(ctx, uid, help.Uuid())
assert.Equal(t, "OK", status)

resp, err := R("DELETE", fmt.Sprintf(`/sessions/%s`, uid), nil)
Expand Down
4 changes: 2 additions & 2 deletions sessions/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package sessions_test

import (
"context"
"github.com/gookit/goutil/strutil"
"github.com/stretchr/testify/assert"
"github.com/weplanx/go/help"
"testing"
"time"
)

func TestSetAndVerify(t *testing.T) {
ctx := context.TODO()
jti := strutil.MicroTimeHexID()
jti := help.Uuid()
status := service.Set(ctx, "dev", jti)
assert.Equal(t, "OK", status)
count := rdb.Exists(ctx, service.Key("dev")).Val()
Expand Down
4 changes: 2 additions & 2 deletions values/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package values

import (
"github.com/bytedance/sonic"
"github.com/gookit/goutil"
"github.com/nats-io/nats.go"
"github.com/weplanx/go/cipher"
"github.com/weplanx/go/help"
"reflect"
"time"
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func (x *Service) Get(keys ...string) (data map[string]interface{}, err error) {
contains[v] = true
}
for key, value := range data {
if len(keys) != 0 && !contains[key] || goutil.IsEmpty(value) {
if len(keys) != 0 && !contains[key] || help.IsEmpty(value) {
delete(data, key)
continue
}
Expand Down

0 comments on commit ae31d83

Please sign in to comment.