diff --git a/CHANGELOG.md b/CHANGELOG.md index d932755..89da474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # CHANGELOG -## v1.1.0 `Doing` +## `TODO` - [ ] 功能:引入事件驱动 - [ ] 功能:完善缓存库 -## v1.0.10 `Doing` +## v1.1.0 - 2023-11-14 +- refactor(hashing): Change the file path for `Hasher` by @flc1125 #30 +- build(deps): bump github.com/redis/go-redis/v9 from 9.2.1 to 9.3.0 by @dependabot #27 +- feat(gorm): Added `LoggerAdapter` by @flc1125 in #28 +- build(deps): bump google.golang.org/grpc from 1.58.0 to 1.58.3 by @dependabot #29 diff --git a/contract/hashing/hasher.go b/contract/hashing/hasher.go deleted file mode 100644 index f5d1efd..0000000 --- a/contract/hashing/hasher.go +++ /dev/null @@ -1,14 +0,0 @@ -package hashing - -type Hasher interface { - // Make a hash value from the given value. - Make(value string) (string, error) - - // MustMake a hash value from the given value. - // If an error occurs, it will panic. - MustMake(value string) string - - // Check the given value matches the given hashed value. - // If you Make() is error, it will return false. - Check(value, hashedValue string) bool -} diff --git a/hashing/hasher.go b/hashing/hasher.go index c9a3721..f5d1efd 100644 --- a/hashing/hasher.go +++ b/hashing/hasher.go @@ -1,40 +1,14 @@ package hashing -import ( - "strconv" +type Hasher interface { + // Make a hash value from the given value. + Make(value string) (string, error) - "github.com/go-packagist/go-kratos-components/contract/hashing" -) + // MustMake a hash value from the given value. + // If an error occurs, it will panic. + MustMake(value string) string -type Hash uint - -const ( - MD5 Hash = 1 + iota - maxHash -) - -var hashes = make([]func() hashing.Hasher, maxHash) - -func (h Hash) Available() bool { - return h < maxHash && hashes[h] != nil -} - -func (h Hash) New() hashing.Hasher { - if h > 0 && h < maxHash { - f := hashes[h] - if f != nil { - return f() - } - } - - panic("hashing: requested hash function #" + strconv.Itoa(int(h)) + " is unavailable") -} - -func Register(h Hash, f func() hashing.Hasher) { - if h > 0 && h < maxHash { - hashes[h] = f - return - } - - panic("hashing: invalid hash") + // Check the given value matches the given hashed value. + // If you Make() is error, it will return false. + Check(value, hashedValue string) bool } diff --git a/hashing/hashing.go b/hashing/hashing.go new file mode 100644 index 0000000..d3ff523 --- /dev/null +++ b/hashing/hashing.go @@ -0,0 +1,38 @@ +package hashing + +import ( + "strconv" +) + +type Hash uint + +const ( + MD5 Hash = 1 + iota + maxHash +) + +var hashes = make([]func() Hasher, maxHash) + +func (h Hash) Available() bool { + return h < maxHash && hashes[h] != nil +} + +func (h Hash) New() Hasher { + if h > 0 && h < maxHash { + f := hashes[h] + if f != nil { + return f() + } + } + + panic("hashing: requested hash function #" + strconv.Itoa(int(h)) + " is unavailable") +} + +func Register(h Hash, f func() Hasher) { + if h > 0 && h < maxHash { + hashes[h] = f + return + } + + panic("hashing: invalid hash") +} diff --git a/hashing/md5/hasher.go b/hashing/md5/hasher.go index 4bbb9bc..68ce4cc 100644 --- a/hashing/md5/hasher.go +++ b/hashing/md5/hasher.go @@ -4,7 +4,6 @@ import ( "crypto/md5" "fmt" - hashingContract "github.com/go-packagist/go-kratos-components/contract/hashing" "github.com/go-packagist/go-kratos-components/hashing" ) @@ -12,7 +11,7 @@ type hasher struct{} var global *hasher -func New() hashingContract.Hasher { +func New() hashing.Hasher { if global == nil { global = &hasher{} }