Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions cmd/pgmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"os"
"os/signal"
"strconv"

// Packages
kong "github.com/alecthomas/kong"
Expand Down Expand Up @@ -69,18 +70,32 @@ func main() {
// PRIVATE METHODS

func (g *Globals) Client() (*httpclient.Client, error) {
scheme := "http"
host, port, err := net.SplitHostPort(g.HTTP.Addr)
if err != nil {
return nil, err
}

// Default host to localhost if empty (e.g., ":8080")
if host == "" {
host = "localhost"
}

// Parse port
portn, err := strconv.ParseUint(port, 10, 16)
if err != nil {
return nil, err
}
if portn == 443 {
scheme = "https"
}

// Client options
opts := []client.ClientOpt{}
if g.Debug {
opts = append(opts, client.OptTrace(os.Stderr, true))
}

// Create a client
url := fmt.Sprintf("http://%s:%s%s", host, port, g.HTTP.Prefix)
return httpclient.New(url, opts...)
// Create a client with the calculated endpoint
return httpclient.New(fmt.Sprintf("%s://%s:%v%s", scheme, host, portn, g.HTTP.Prefix), opts...)
}