From ff89dc7970951004a126bb9b0cf71efb17f70ec9 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 15 Oct 2024 10:48:35 +0200 Subject: [PATCH] feat: do not define api version with server address attribute --- .gitignore | 4 ++-- flake.nix | 1 + pkg/command/cmd.go | 2 +- pkg/command/handle.go | 13 ++++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 613c1b3..b98f0ad 100755 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ coverage.out -/bin -/dist +bin/ +dist/ diff --git a/flake.nix b/flake.nix index 9192061..7d41e39 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,7 @@ packages = with pkgs; [ bingo gnumake + goreleaser nixpkgs-fmt ]; diff --git a/pkg/command/cmd.go b/pkg/command/cmd.go index 0d77ce7..ba451e9 100644 --- a/pkg/command/cmd.go +++ b/pkg/command/cmd.go @@ -11,7 +11,7 @@ import ( ) const ( - defaultServerAddress = "http://localhost:8080/api/v1" + defaultServerAddress = "http://localhost:8080/api" ) var ( diff --git a/pkg/command/handle.go b/pkg/command/handle.go index 3175b45..b2e1e4b 100644 --- a/pkg/command/handle.go +++ b/pkg/command/handle.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "os" + "strings" "text/template" "github.com/gopad/gopad-go/gopad" @@ -30,7 +31,17 @@ func Handle(ccmd *cobra.Command, args []string, fn HandleFunc) { os.Exit(1) } - server, err := url.Parse(viper.GetString("server.address")) + serverAddress := viper.GetString("server.address") + + if strings.HasSuffix(serverAddress, "/") { + serverAddress = fmt.Sprintf("%sv1", serverAddress) + } else { + serverAddress = fmt.Sprintf("%s/v1", serverAddress) + } + + server, err := url.Parse( + serverAddress, + ) if err != nil { fmt.Fprintf(os.Stderr, "Error: Invalid server address, bad format?\n")