diff --git a/assert/log_test.go b/assert/log_test.go new file mode 100644 index 0000000..7d86208 --- /dev/null +++ b/assert/log_test.go @@ -0,0 +1,7 @@ +package assert + +import "testing" + +func Test_logDepth(t *testing.T) { + logDepth(t, "test log", 1) +} diff --git a/cmd/checksum/main.go b/cmd/checksum/main.go index 40d9f6b..f12df35 100644 --- a/cmd/checksum/main.go +++ b/cmd/checksum/main.go @@ -3,41 +3,16 @@ package main import ( "errors" "fmt" - "github.com/tursom/checksum/checksum" + "github.com/tursom/checksum/hash" "io" "io/fs" "os" "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() { path, checksumType := readConfig() - doCheck(path, hashFuncs[checksumType-1]) + doCheck(path, hash.Funcs[checksumType-1]) waitExit() } @@ -50,7 +25,7 @@ func readConfig() (string, uint) { } 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.Print(">>> ") @@ -61,11 +36,11 @@ func readConfig() (string, uint) { return path, checksumType } -func doCheck(path string, factory func() checksum.Func) { +func doCheck(path string, factory func() hash.Func) { checkFile(path, factory) } -func checkFile(path string, factory func() checksum.Func) { +func checkFile(path string, factory func() hash.Func) { file, err := os.Open(path) if err != nil { panic(err) diff --git a/checksum/adler32.go b/hash/adler32.go similarity index 95% rename from checksum/adler32.go rename to hash/adler32.go index 55d40eb..3ba5cbc 100644 --- a/checksum/adler32.go +++ b/hash/adler32.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "hash" diff --git a/checksum/adler32_test.go b/hash/adler32_test.go similarity index 98% rename from checksum/adler32_test.go rename to hash/adler32_test.go index 005c910..3b45174 100644 --- a/checksum/adler32_test.go +++ b/hash/adler32_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc.go b/hash/crc.go similarity index 99% rename from checksum/crc.go rename to hash/crc.go index 464abd6..339335d 100644 --- a/checksum/crc.go +++ b/hash/crc.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "hash" diff --git a/checksum/crc32castagnoli_test.go b/hash/crc32castagnoli_test.go similarity index 98% rename from checksum/crc32castagnoli_test.go rename to hash/crc32castagnoli_test.go index c3767ed..7b9acc3 100644 --- a/checksum/crc32castagnoli_test.go +++ b/hash/crc32castagnoli_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc32ieee_test.go b/hash/crc32ieee_test.go similarity index 98% rename from checksum/crc32ieee_test.go rename to hash/crc32ieee_test.go index 6d42ac0..f90c07d 100644 --- a/checksum/crc32ieee_test.go +++ b/hash/crc32ieee_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc32koopman_test.go b/hash/crc32koopman_test.go similarity index 98% rename from checksum/crc32koopman_test.go rename to hash/crc32koopman_test.go index d33569a..7036f59 100644 --- a/checksum/crc32koopman_test.go +++ b/hash/crc32koopman_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc64ecma_test.go b/hash/crc64ecma_test.go similarity index 98% rename from checksum/crc64ecma_test.go rename to hash/crc64ecma_test.go index 2fda023..e93dae6 100644 --- a/checksum/crc64ecma_test.go +++ b/hash/crc64ecma_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc64iso_test.go b/hash/crc64iso_test.go similarity index 98% rename from checksum/crc64iso_test.go rename to hash/crc64iso_test.go index d7e67d0..1f32ebd 100644 --- a/checksum/crc64iso_test.go +++ b/hash/crc64iso_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/crc_test.go b/hash/crc_test.go similarity index 97% rename from checksum/crc_test.go rename to hash/crc_test.go index 59dc7d8..b01da41 100644 --- a/checksum/crc_test.go +++ b/hash/crc_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/def.go b/hash/def.go similarity index 85% rename from checksum/def.go rename to hash/def.go index b7fe54f..435d063 100644 --- a/checksum/def.go +++ b/hash/def.go @@ -1,4 +1,4 @@ -package checksum +package hash import "fmt" diff --git a/checksum/fnv.go b/hash/fnv.go similarity index 99% rename from checksum/fnv.go rename to hash/fnv.go index dc6f82c..29677a9 100644 --- a/checksum/fnv.go +++ b/hash/fnv.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "hash" diff --git a/checksum/fnv128_test.go b/hash/fnv128_test.go similarity index 98% rename from checksum/fnv128_test.go rename to hash/fnv128_test.go index c6c8de0..0220a50 100644 --- a/checksum/fnv128_test.go +++ b/hash/fnv128_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/fnv128a_test.go b/hash/fnv128a_test.go similarity index 98% rename from checksum/fnv128a_test.go rename to hash/fnv128a_test.go index ce3d786..d58b79e 100644 --- a/checksum/fnv128a_test.go +++ b/hash/fnv128a_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/fnv32_test.go b/hash/fnv32_test.go similarity index 98% rename from checksum/fnv32_test.go rename to hash/fnv32_test.go index 401d070..c6dc867 100644 --- a/checksum/fnv32_test.go +++ b/hash/fnv32_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/fnv32a_test.go b/hash/fnv32a_test.go similarity index 98% rename from checksum/fnv32a_test.go rename to hash/fnv32a_test.go index 5b32121..70d6ad3 100644 --- a/checksum/fnv32a_test.go +++ b/hash/fnv32a_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/fnv64_test.go b/hash/fnv64_test.go similarity index 98% rename from checksum/fnv64_test.go rename to hash/fnv64_test.go index 4444153..87848c5 100644 --- a/checksum/fnv64_test.go +++ b/hash/fnv64_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/fnv64a_test.go b/hash/fnv64a_test.go similarity index 98% rename from checksum/fnv64a_test.go rename to hash/fnv64a_test.go index 773aa90..d39b60e 100644 --- a/checksum/fnv64a_test.go +++ b/hash/fnv64a_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/hash/funcs.go b/hash/funcs.go new file mode 100644 index 0000000..db86bf1 --- /dev/null +++ b/hash/funcs.go @@ -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{} }, + } +) diff --git a/checksum/md5.go b/hash/md5.go similarity index 94% rename from checksum/md5.go rename to hash/md5.go index ddfd8f7..a706bc9 100644 --- a/checksum/md5.go +++ b/hash/md5.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/md5" diff --git a/checksum/md5_test.go b/hash/md5_test.go similarity index 97% rename from checksum/md5_test.go rename to hash/md5_test.go index c834b61..d794f96 100644 --- a/checksum/md5_test.go +++ b/hash/md5_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/md5" diff --git a/checksum/murmur3.go b/hash/murmur3.go similarity index 98% rename from checksum/murmur3.go rename to hash/murmur3.go index 39529c1..bf5a31d 100644 --- a/checksum/murmur3.go +++ b/hash/murmur3.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "hash" diff --git a/checksum/murmur3_128_test.go b/hash/murmur3_128_test.go similarity index 98% rename from checksum/murmur3_128_test.go rename to hash/murmur3_128_test.go index 14f5171..b79a443 100644 --- a/checksum/murmur3_128_test.go +++ b/hash/murmur3_128_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/murmur3_32_test.go b/hash/murmur3_32_test.go similarity index 98% rename from checksum/murmur3_32_test.go rename to hash/murmur3_32_test.go index f2e96b9..c755bfb 100644 --- a/checksum/murmur3_32_test.go +++ b/hash/murmur3_32_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/murmur3_64_test.go b/hash/murmur3_64_test.go similarity index 98% rename from checksum/murmur3_64_test.go rename to hash/murmur3_64_test.go index 2cf7134..e0d5239 100644 --- a/checksum/murmur3_64_test.go +++ b/hash/murmur3_64_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/tursom/checksum/assert" diff --git a/checksum/sha1.go b/hash/sha1.go similarity index 94% rename from checksum/sha1.go rename to hash/sha1.go index 2ac8cbb..1a2328b 100644 --- a/checksum/sha1.go +++ b/hash/sha1.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha1" diff --git a/checksum/sha1_test.go b/hash/sha1_test.go similarity index 97% rename from checksum/sha1_test.go rename to hash/sha1_test.go index 62fe9b3..84b1440 100644 --- a/checksum/sha1_test.go +++ b/hash/sha1_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha1" diff --git a/checksum/sha256.go b/hash/sha256.go similarity index 95% rename from checksum/sha256.go rename to hash/sha256.go index 25cf267..8137fb7 100644 --- a/checksum/sha256.go +++ b/hash/sha256.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha256" diff --git a/checksum/sha256_test.go b/hash/sha256_test.go similarity index 98% rename from checksum/sha256_test.go rename to hash/sha256_test.go index c9d1d39..c1cb1d6 100644 --- a/checksum/sha256_test.go +++ b/hash/sha256_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha256" diff --git a/checksum/sha512.go b/hash/sha512.go similarity index 95% rename from checksum/sha512.go rename to hash/sha512.go index 4db8c5b..21ae16f 100644 --- a/checksum/sha512.go +++ b/hash/sha512.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha512" diff --git a/checksum/sha512_test.go b/hash/sha512_test.go similarity index 98% rename from checksum/sha512_test.go rename to hash/sha512_test.go index 387ac07..48eabd6 100644 --- a/checksum/sha512_test.go +++ b/hash/sha512_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "crypto/sha512" diff --git a/checksum/xxh.go b/hash/xxh.go similarity index 95% rename from checksum/xxh.go rename to hash/xxh.go index bc5a686..93c74f1 100644 --- a/checksum/xxh.go +++ b/hash/xxh.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/cespare/xxhash" diff --git a/checksum/xxhash64_test.go b/hash/xxhash64_test.go similarity index 98% rename from checksum/xxhash64_test.go rename to hash/xxhash64_test.go index 0d99342..cc83cb6 100644 --- a/checksum/xxhash64_test.go +++ b/hash/xxhash64_test.go @@ -1,4 +1,4 @@ -package checksum +package hash import ( "github.com/cespare/xxhash"