Skip to content

Commit 4b60de0

Browse files
committed
update upstreams to format ipv6 adddress for nginx plus
1 parent 2cb44de commit 4b60de0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

internal/mode/static/nginx/config/convert.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ func ConvertEndpoints(eps []resolver.Endpoint) []ngxclient.UpstreamServer {
1818
port = fmt.Sprintf(":%d", ep.Port)
1919
}
2020

21+
format := "%s%s"
22+
if ep.IPv6 {
23+
format = "[%s]%s"
24+
}
25+
2126
server := ngxclient.UpstreamServer{
22-
Server: fmt.Sprintf("%s%s", ep.Address, port),
27+
Server: fmt.Sprintf(format, ep.Address, port),
2328
}
2429

2530
servers = append(servers, server)

internal/mode/static/nginx/config/convert_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ func TestConvertEndpoints(t *testing.T) {
1919
Address: "5.6.7.8",
2020
Port: 0,
2121
},
22+
{
23+
Address: "2001:db8::1",
24+
Port: 443,
25+
IPv6: true,
26+
},
2227
}
2328

2429
expUpstreams := []ngxclient.UpstreamServer{
@@ -28,6 +33,9 @@ func TestConvertEndpoints(t *testing.T) {
2833
{
2934
Server: "5.6.7.8",
3035
},
36+
{
37+
Server: "[2001:db8::1]:443",
38+
},
3139
}
3240

3341
g := NewWithT(t)

0 commit comments

Comments
 (0)