rename package checksum to hash

This commit is contained in:
2023-08-01 16:27:27 +08:00
parent e461eca3fc
commit 203c5e088c
34 changed files with 69 additions and 61 deletions

7
assert/log_test.go Normal file
View File

@@ -0,0 +1,7 @@
package assert
import "testing"
func Test_logDepth(t *testing.T) {
logDepth(t, "test log", 1)
}

View File

@@ -3,41 +3,16 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/tursom/checksum/checksum" "github.com/tursom/checksum/hash"
"io" "io"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
) )
var (
hashFuncs = []func() checksum.Func{
func() checksum.Func { return &checksum.Md5{} },
func() checksum.Func { return &checksum.Sha1{} },
func() checksum.Func { return &checksum.Sha256{} },
func() checksum.Func { return &checksum.Sha512{} },
func() checksum.Func { return &checksum.Murmur332{} },
func() checksum.Func { return &checksum.Murmur364{} },
func() checksum.Func { return &checksum.Murmur3128{} },
func() checksum.Func { return &checksum.Adler32{} },
func() checksum.Func { return &checksum.Crc32Ieee{} },
func() checksum.Func { return &checksum.Crc32Castagnoli{} },
func() checksum.Func { return &checksum.Crc32Koopman{} },
func() checksum.Func { return &checksum.Crc64Iso{} },
func() checksum.Func { return &checksum.Crc64Ecma{} },
func() checksum.Func { return &checksum.Fnv32{} },
func() checksum.Func { return &checksum.Fnv32a{} },
func() checksum.Func { return &checksum.Fnv64{} },
func() checksum.Func { return &checksum.Fnv64a{} },
func() checksum.Func { return &checksum.Fnv128{} },
func() checksum.Func { return &checksum.Fnv128a{} },
func() checksum.Func { return &checksum.Xxh64{} },
}
)
func main() { func main() {
path, checksumType := readConfig() path, checksumType := readConfig()
doCheck(path, hashFuncs[checksumType-1]) doCheck(path, hash.Funcs[checksumType-1])
waitExit() waitExit()
} }
@@ -50,7 +25,7 @@ func readConfig() (string, uint) {
} }
fmt.Println("Please select checksum type:") fmt.Println("Please select checksum type:")
for i, f := range hashFuncs { for i, f := range hash.Funcs {
fmt.Printf("%d. %s\n", i+1, f().String()) fmt.Printf("%d. %s\n", i+1, f().String())
} }
fmt.Print(">>> ") fmt.Print(">>> ")
@@ -61,11 +36,11 @@ func readConfig() (string, uint) {
return path, checksumType return path, checksumType
} }
func doCheck(path string, factory func() checksum.Func) { func doCheck(path string, factory func() hash.Func) {
checkFile(path, factory) checkFile(path, factory)
} }
func checkFile(path string, factory func() checksum.Func) { func checkFile(path string, factory func() hash.Func) {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"hash" "hash"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"hash" "hash"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import "fmt" import "fmt"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"hash" "hash"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

26
hash/funcs.go Normal file
View File

@@ -0,0 +1,26 @@
package hash
var (
Funcs = []func() Func{
func() Func { return &Md5{} },
func() Func { return &Sha1{} },
func() Func { return &Sha256{} },
func() Func { return &Sha512{} },
func() Func { return &Murmur332{} },
func() Func { return &Murmur364{} },
func() Func { return &Murmur3128{} },
func() Func { return &Adler32{} },
func() Func { return &Crc32Ieee{} },
func() Func { return &Crc32Castagnoli{} },
func() Func { return &Crc32Koopman{} },
func() Func { return &Crc64Iso{} },
func() Func { return &Crc64Ecma{} },
func() Func { return &Fnv32{} },
func() Func { return &Fnv32a{} },
func() Func { return &Fnv64{} },
func() Func { return &Fnv64a{} },
func() Func { return &Fnv128{} },
func() Func { return &Fnv128a{} },
func() Func { return &Xxh64{} },
}
)

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/md5" "crypto/md5"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/md5" "crypto/md5"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"hash" "hash"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/tursom/checksum/assert" "github.com/tursom/checksum/assert"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha1" "crypto/sha1"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha1" "crypto/sha1"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha256" "crypto/sha256"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha256" "crypto/sha256"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha512" "crypto/sha512"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"crypto/sha512" "crypto/sha512"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/cespare/xxhash" "github.com/cespare/xxhash"

View File

@@ -1,4 +1,4 @@
package checksum package hash
import ( import (
"github.com/cespare/xxhash" "github.com/cespare/xxhash"