From f1dff3e43433377ddc6e6283a42ae2d62bcc9116 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Nov 2022 12:40:28 +0100 Subject: [PATCH 1/2] registry: use consts for some defaults Signed-off-by: Sebastiaan van Stijn --- registry/registry.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index 8eebe6a4f..e2e35d58a 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -72,15 +72,16 @@ var defaultCipherSuites = []uint16{ tls.TLS_AES_256_GCM_SHA384, } -// maps tls version strings to constants -var ( - defaultTLSVersionStr = "tls1.2" - tlsVersions = map[string]uint16{ - // user specified values - "tls1.2": tls.VersionTLS12, - "tls1.3": tls.VersionTLS13, - } -) +const defaultTLSVersionStr = "tls1.2" + +// tlsVersions maps user-specified values to tls version constants. +var tlsVersions = map[string]uint16{ + "tls1.2": tls.VersionTLS12, + "tls1.3": tls.VersionTLS13, +} + +// defaultLogFormatter is the default formatter to use for logs. +const defaultLogFormatter = "text" // this channel gets notified when process receives signal. It is global to ease unit testing var quit = make(chan os.Signal, 1) @@ -131,6 +132,7 @@ var ServeCmd = &cobra.Command{ } // A Registry represents a complete instance of the registry. +// // TODO(aaronl): It might make sense for Registry to become an interface. type Registry struct { config *configuration.Configuration @@ -347,7 +349,7 @@ func configureLogging(ctx context.Context, config *configuration.Configuration) formatter := config.Log.Formatter if formatter == "" { - formatter = "text" // default formatter + formatter = defaultLogFormatter } switch formatter { From b73c0380003a12d0c6c7e422152c806d6eb6d07d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Nov 2022 00:05:39 +0100 Subject: [PATCH 2/2] registry: configureLogging() simplify logic a bit Signed-off-by: Sebastiaan van Stijn --- registry/registry.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/registry/registry.go b/registry/registry.go index e2e35d58a..c6f33e1a0 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -367,16 +367,10 @@ func configureLogging(ctx context.Context, config *configuration.Configuration) Formatter: &logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano}, }) default: - // just let the library use default on empty string. - if config.Log.Formatter != "" { - return ctx, fmt.Errorf("unsupported logging formatter: %q", config.Log.Formatter) - } - } - - if config.Log.Formatter != "" { - logrus.Debugf("using %q logging formatter", config.Log.Formatter) + return ctx, fmt.Errorf("unsupported logging formatter: %q", formatter) } + logrus.Debugf("using %q logging formatter", formatter) if len(config.Log.Fields) > 0 { // build up the static fields, if present. var fields []interface{}