From f3657dc1892b41d575a8bd2c518044b70446bbe9 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Sat, 8 Jan 2022 23:42:32 +0100 Subject: [PATCH] refactor: Use consistent naming scheme for config keys --- cmd/stfs/cmd/operation_archive.go | 2 +- cmd/stfs/cmd/operation_update.go | 2 +- cmd/stfs/cmd/serve_ftp.go | 2 +- examples/full/main.go | 4 ++-- examples/simple/main.go | 2 +- pkg/compression/compress.go | 36 +++++++++++++++---------------- pkg/config/constants.go | 8 +++---- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cmd/stfs/cmd/operation_archive.go b/cmd/stfs/cmd/operation_archive.go index b28c57e..5f8f024 100644 --- a/cmd/stfs/cmd/operation_archive.go +++ b/cmd/stfs/cmd/operation_archive.go @@ -169,7 +169,7 @@ func init() { operationArchiveCmd.PersistentFlags().IntP(recordSizeFlag, "z", 20, "Amount of 512-bit blocks per record") operationArchiveCmd.PersistentFlags().StringP(fromFlag, "f", ".", "File or directory to archive") operationArchiveCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Start writing from the start instead of from the end of the tape or tar file") - operationArchiveCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalanced, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalanced, config.KnownCompressionLevels)) + operationArchiveCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalancedKey, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalancedKey, config.KnownCompressionLevels)) operationArchiveCmd.PersistentFlags().StringP(recipientFlag, "r", "", "Path to public key of recipient to encrypt for") operationArchiveCmd.PersistentFlags().StringP(identityFlag, "i", "", "Path to private key to sign with") operationArchiveCmd.PersistentFlags().StringP(passwordFlag, "p", "", "Password for the private key") diff --git a/cmd/stfs/cmd/operation_update.go b/cmd/stfs/cmd/operation_update.go index 31e0956..0bcf298 100644 --- a/cmd/stfs/cmd/operation_update.go +++ b/cmd/stfs/cmd/operation_update.go @@ -160,7 +160,7 @@ func init() { operationUpdateCmd.PersistentFlags().IntP(recordSizeFlag, "z", 20, "Amount of 512-bit blocks per record") operationUpdateCmd.PersistentFlags().StringP(fromFlag, "f", "", "Path of the file or directory to update") operationUpdateCmd.PersistentFlags().BoolP(overwriteFlag, "o", false, "Replace the content on the tape or tar file") - operationUpdateCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalanced, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalanced, config.KnownCompressionLevels)) + operationUpdateCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalancedKey, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalancedKey, config.KnownCompressionLevels)) operationUpdateCmd.PersistentFlags().StringP(recipientFlag, "r", "", "Path to public key of recipient to encrypt for") operationUpdateCmd.PersistentFlags().StringP(identityFlag, "i", "", "Path to private key to sign with") operationUpdateCmd.PersistentFlags().StringP(passwordFlag, "p", "", "Password for the private key") diff --git a/cmd/stfs/cmd/serve_ftp.go b/cmd/stfs/cmd/serve_ftp.go index e0831d8..de668ce 100644 --- a/cmd/stfs/cmd/serve_ftp.go +++ b/cmd/stfs/cmd/serve_ftp.go @@ -247,7 +247,7 @@ func init() { serveFTPCmd.PersistentFlags().StringP(signaturePasswordFlag, "x", "", "Password for the private key to sign with") serveFTPCmd.PersistentFlags().StringP(signatureRecipientFlag, "r", "", "Path to the public key to verify with") - serveFTPCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalanced, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalanced, config.KnownCompressionLevels)) + serveFTPCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalancedKey, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalancedKey, config.KnownCompressionLevels)) serveFTPCmd.PersistentFlags().StringP(laddrFlag, "a", "localhost:1337", "Listen address") serveFTPCmd.PersistentFlags().StringP(cacheFileSystemFlag, "n", config.NoneKey, fmt.Sprintf("File system cache to use (default %v, available are %v)", config.NoneKey, config.KnownFileSystemCacheTypes)) serveFTPCmd.PersistentFlags().StringP(cacheWriteFlag, "q", config.WriteCacheTypeFile, fmt.Sprintf("Write cache to use (default %v, available are %v)", config.WriteCacheTypeFile, config.KnownWriteCacheTypes)) diff --git a/examples/full/main.go b/examples/full/main.go index a2e73d6..6345bfa 100644 --- a/examples/full/main.go +++ b/examples/full/main.go @@ -214,10 +214,10 @@ func main() { encryptionPassword := "testEncryptionPassword" compression := config.CompressionFormatZStandardKey - compressionLevel := config.CompressionLevelFastest + compressionLevel := config.CompressionLevelFastestKey - writeCacheDir := filepath.Join(tmp, "write-cache") writeCache := config.WriteCacheTypeFile + writeCacheDir := filepath.Join(tmp, "write-cache") fileSystemCache := config.FileSystemCacheTypeDir fileSystemCacheDir := filepath.Join(tmp, "filesystem-cache") diff --git a/examples/simple/main.go b/examples/simple/main.go index d64147a..59a57e5 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -91,7 +91,7 @@ func main() { Metadata: metadataPersister, }, - config.CompressionLevelFastest, + config.CompressionLevelFastestKey, func() (cache.WriteCache, func() error, error) { return cache.NewCacheWrite( *writeCacheFlag, diff --git a/pkg/compression/compress.go b/pkg/compression/compress.go index 62597ed..04b0e87 100644 --- a/pkg/compression/compress.go +++ b/pkg/compression/compress.go @@ -37,11 +37,11 @@ func Compress( l := gzip.DefaultCompression switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = gzip.BestSpeed - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = gzip.DefaultCompression - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = gzip.BestCompression default: return nil, config.ErrCompressionLevelUnsupported @@ -56,11 +56,11 @@ func Compress( l := pgzip.DefaultCompression switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = pgzip.BestSpeed - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = pgzip.DefaultCompression - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = pgzip.BestCompression default: return nil, config.ErrCompressionLevelUnsupported @@ -70,11 +70,11 @@ func Compress( case config.CompressionFormatLZ4Key: l := lz4.Level5 switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = lz4.Level1 - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = lz4.Level5 - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = lz4.Level9 default: return nil, config.ErrCompressionLevelUnsupported @@ -108,11 +108,11 @@ func Compress( case config.CompressionFormatZStandardKey: l := zstd.SpeedDefault switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = zstd.SpeedFastest - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = zstd.SpeedDefault - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = zstd.SpeedBestCompression default: return nil, config.ErrCompressionLevelUnsupported @@ -136,11 +136,11 @@ func Compress( l := brotli.DefaultCompression switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = brotli.BestSpeed - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = brotli.DefaultCompression - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = brotli.BestCompression default: return nil, config.ErrCompressionLevelUnsupported @@ -154,11 +154,11 @@ func Compress( case config.CompressionFormatBzip2ParallelKey: l := bzip2.DefaultCompression switch compressionLevel { - case config.CompressionLevelFastest: + case config.CompressionLevelFastestKey: l = bzip2.BestSpeed - case config.CompressionLevelBalanced: + case config.CompressionLevelBalancedKey: l = bzip2.DefaultCompression - case config.CompressionLevelSmallest: + case config.CompressionLevelSmallestKey: l = bzip2.BestCompression default: return nil, config.ErrCompressionLevelUnsupported diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 2cf7e00..436b98c 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -17,9 +17,9 @@ const ( SignatureFormatMinisignKey = "minisign" SignatureFormatPGPKey = "pgp" - CompressionLevelFastest = "fastest" - CompressionLevelBalanced = "balanced" - CompressionLevelSmallest = "smallest" + CompressionLevelFastestKey = "fastest" + CompressionLevelBalancedKey = "balanced" + CompressionLevelSmallestKey = "smallest" HeaderEventTypeArchive = "archive" HeaderEventTypeDelete = "delete" @@ -37,7 +37,7 @@ const ( ) var ( - KnownCompressionLevels = []string{CompressionLevelFastest, CompressionLevelBalanced, CompressionLevelSmallest} + KnownCompressionLevels = []string{CompressionLevelFastestKey, CompressionLevelBalancedKey, CompressionLevelSmallestKey} KnownCompressionFormats = []string{NoneKey, CompressionFormatGZipKey, CompressionFormatParallelGZipKey, CompressionFormatLZ4Key, CompressionFormatZStandardKey, CompressionFormatBrotliKey, CompressionFormatBzip2Key, CompressionFormatBzip2ParallelKey}