From f024832a8c01507eb4618ea3ef7b1bed1ba8ab88 Mon Sep 17 00:00:00 2001 From: KenyC Date: Thu, 31 Oct 2024 11:58:38 +0100 Subject: [PATCH 1/3] Displayed URL in message --- cmd/serve/serve.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index daa7446..adf9c0d 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -90,8 +90,21 @@ func (c *command) Run(ctx context.Context) error { go func() { serveTLS := *c.tlsCertPath != "" && *c.tlsKeyPath != "" - ancli.PrintfOK("now serving directory: '%v' on port: '%v', mirror dir is: '%v', tls: %v, certPath: '%v', keyPath: '%v'", - c.masterPath, *c.port, c.mirrorPath, serveTLS, *c.tlsCertPath, *c.tlsKeyPath) + hostname := "localhost" // default hostname + protocol := "http" + if *c.tlsCertPath != "" && *c.tlsKeyPath != "" { + protocol = "https" + } + baseURL := fmt.Sprintf("%s://%s:%d", protocol, hostname, *c.port) + + ancli.PrintfOK("Server started successfully:") + ancli.PrintfOK("- URL: %s", baseURL) + ancli.PrintfOK("- Serving directory: '%v'", c.masterPath) + ancli.PrintfOK("- Mirror directory: '%v'", c.mirrorPath) + if serveTLS { + ancli.PrintfOK("- TLS enabled (cert: '%v', key: '%v')", *c.tlsCertPath, *c.tlsKeyPath) + } + var err error if serveTLS { err = s.ListenAndServeTLS(*c.tlsCertPath, *c.tlsKeyPath) From efec37e17cb5d9d77fc755e5ff674529d8753cd9 Mon Sep 17 00:00:00 2001 From: KenyC Date: Thu, 31 Oct 2024 12:13:27 +0100 Subject: [PATCH 2/3] Display "TLS disabled" when key or cert isn't present --- cmd/serve/serve.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index adf9c0d..335a47b 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -103,6 +103,8 @@ func (c *command) Run(ctx context.Context) error { ancli.PrintfOK("- Mirror directory: '%v'", c.mirrorPath) if serveTLS { ancli.PrintfOK("- TLS enabled (cert: '%v', key: '%v')", *c.tlsCertPath, *c.tlsKeyPath) + } else { + ancli.PrintfOK("- TLS disabled") } var err error From 1c4504982a058a3a6908609875c27b3883509f1d Mon Sep 17 00:00:00 2001 From: KenyC Date: Thu, 31 Oct 2024 17:09:10 +0100 Subject: [PATCH 3/3] Replaced complex condition with already defined serveTLS --- cmd/serve/serve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/serve/serve.go b/cmd/serve/serve.go index 335a47b..bc5a731 100644 --- a/cmd/serve/serve.go +++ b/cmd/serve/serve.go @@ -92,7 +92,7 @@ func (c *command) Run(ctx context.Context) error { hostname := "localhost" // default hostname protocol := "http" - if *c.tlsCertPath != "" && *c.tlsKeyPath != "" { + if serveTLS { protocol = "https" } baseURL := fmt.Sprintf("%s://%s:%d", protocol, hostname, *c.port)