From 7e0d60c30c7b8d3f6ad6d94f83dadc09842f8915 Mon Sep 17 00:00:00 2001 From: seternate Date: Tue, 21 May 2024 20:45:18 +0200 Subject: [PATCH] Fix startup if scheme is missing in server URL If the scheme in the server URL is missing 'http' is added as default scheme and the url is parsed again. With this behaviour the user does not need to enter the scheme if it would be 'http'. --- pkg/controller/controller.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 9f3c4d9..1accb75 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -37,11 +37,16 @@ func NewController(ctx context.Context) *Controller { if err != nil { log.Fatal().Err(err).Send() } - url, err := url.Parse(settings.ServerURL) + + u, err := url.Parse(settings.ServerURL) + if len(u.Host) == 0 { + u, err = url.Parse("http://" + settings.ServerURL) + } if err != nil { log.Fatal().Err(err).Str("url", settings.ServerURL).Msg("failed to parse server URL") } - client := api.NewClient(url, timeout) + + client := api.NewClient(u, timeout) if err != nil { log.Fatal().Err(err).Msg("failed to create API client") }