Skip to content

Commit c44b87f

Browse files
committed
fix: alphabetize imports, bracket IPv6 hostnames, clarify SQL host
- Move env import to correct alphabetical position - Wrap IPv6 literal hostnames in brackets for valid URL construction - Add comment explaining why connectionStringHost is separate from NITRIC_HOSTNAME
1 parent bd70894 commit c44b87f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/cloud/cloud.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cloud
1919
import (
2020
"fmt"
2121
"io"
22+
"strings"
2223
"sync"
2324

2425
"google.golang.org/grpc"
@@ -35,10 +36,10 @@ import (
3536
"github.com/nitrictech/cli/pkg/cloud/secrets"
3637
"github.com/nitrictech/cli/pkg/cloud/sql"
3738
"github.com/nitrictech/cli/pkg/cloud/storage"
39+
"github.com/nitrictech/cli/pkg/cloud/env"
3840
"github.com/nitrictech/cli/pkg/cloud/topics"
3941
"github.com/nitrictech/cli/pkg/cloud/websites"
4042
"github.com/nitrictech/cli/pkg/cloud/websockets"
41-
"github.com/nitrictech/cli/pkg/cloud/env"
4243
"github.com/nitrictech/cli/pkg/grpcx"
4344
"github.com/nitrictech/cli/pkg/netx"
4445
"github.com/nitrictech/cli/pkg/project/dockerhost"
@@ -258,6 +259,11 @@ type LocalCloudOptions struct {
258259
func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
259260
hostname := env.NITRIC_HOSTNAME.String()
260261

262+
// Bracket IPv6 literals for use in URLs (RFC 3986)
263+
if strings.Contains(hostname, ":") && !strings.HasPrefix(hostname, "[") {
264+
hostname = "[" + hostname + "]"
265+
}
266+
261267
localTopics, err := topics.NewLocalTopicsService()
262268
if err != nil {
263269
return nil, err
@@ -314,6 +320,9 @@ func New(projectName string, opts LocalCloudOptions) (*LocalCloud, error) {
314320
return nil, err
315321
}
316322

323+
// connectionStringHost controls how application services reach the Postgres container,
324+
// which is distinct from NITRIC_HOSTNAME (how callers reach the Nitric backend).
325+
// Postgres is its own container with host-mapped ports, so it needs separate addressing.
317326
connectionStringHost := "localhost"
318327

319328
// Use the host.docker.internal address for connection strings with local cloud run mode

0 commit comments

Comments
 (0)