Skip to content

Commit

Permalink
feat: do not define api version with server address attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tboerger committed Oct 15, 2024
1 parent 440deea commit ff89dc7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

coverage.out

/bin
/dist
bin/
dist/
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
packages = with pkgs; [
bingo
gnumake
goreleaser
nixpkgs-fmt
];

Expand Down
2 changes: 1 addition & 1 deletion pkg/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
defaultServerAddress = "http://localhost:8080/api/v1"
defaultServerAddress = "http://localhost:8080/api"
)

var (
Expand Down
13 changes: 12 additions & 1 deletion pkg/command/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"text/template"

"github.com/gopad/gopad-go/gopad"
Expand All @@ -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")
Expand Down

0 comments on commit ff89dc7

Please sign in to comment.