Skip to content

Commit 078f713

Browse files
committed
Updated client logic for connecting to https endpoints
1 parent 09aa7f3 commit 078f713

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/pgmanager/main.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"os"
88
"os/signal"
9+
"strconv"
910

1011
// Packages
1112
kong "github.com/alecthomas/kong"
@@ -69,18 +70,32 @@ func main() {
6970
// PRIVATE METHODS
7071

7172
func (g *Globals) Client() (*httpclient.Client, error) {
73+
scheme := "http"
7274
host, port, err := net.SplitHostPort(g.HTTP.Addr)
7375
if err != nil {
7476
return nil, err
7577
}
7678

79+
// Default host to localhost if empty (e.g., ":8080")
80+
if host == "" {
81+
host = "localhost"
82+
}
83+
84+
// Parse port
85+
portn, err := strconv.ParseUint(port, 10, 16)
86+
if err != nil {
87+
return nil, err
88+
}
89+
if portn == 443 {
90+
scheme = "https"
91+
}
92+
7793
// Client options
7894
opts := []client.ClientOpt{}
7995
if g.Debug {
8096
opts = append(opts, client.OptTrace(os.Stderr, true))
8197
}
8298

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

0 commit comments

Comments
 (0)