-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(hashing): Change the file path for
Hasher
(#30)
* refactor(hashing): Change the file path for `Hasher` * refactor(hashing): Change the file path for `Hasher` * refactor(hashing): Change the file path for `Hasher`
- Loading branch information
Showing
5 changed files
with
54 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters