feat(host): complete launcher and gateway multi-host binding support

- add shared netbind planning for strict tcp4/tcp6 bind semantics
- support launcher/gateway host env overrides and launcher-to-gateway forwarding
- cover host binding and forwarding with network and subprocess env tests
This commit is contained in:
lc6464
2026-04-14 12:43:49 +08:00
parent 7b38d437ba
commit d4d652b455
24 changed files with 1625 additions and 1002 deletions
+8 -5
View File
@@ -3,7 +3,6 @@ package gateway
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
@@ -11,15 +10,19 @@ import (
"github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/gateway"
"github.com/sipeed/picoclaw/pkg/logger"
"github.com/sipeed/picoclaw/pkg/netbind"
"github.com/sipeed/picoclaw/pkg/utils"
)
func resolveGatewayHostOverride(explicit bool, host string) (string, error) {
host = strings.TrimSpace(host)
if explicit && host == "" {
return "", fmt.Errorf("the --host option cannot be empty")
if !explicit {
return "", nil
}
return host, nil
normalized, err := netbind.NormalizeHostInput(host)
if err != nil {
return "", fmt.Errorf("invalid --host value: %w", err)
}
return normalized, nil
}
func NewGatewayCommand() *cobra.Command {
@@ -43,6 +43,7 @@ func TestResolveGatewayHostOverride(t *testing.T) {
{name: "implicit empty host is allowed", explicit: false, host: "", wantHost: "", wantErr: false},
{name: "explicit empty host rejected", explicit: true, host: " ", wantHost: "", wantErr: true},
{name: "explicit localhost kept", explicit: true, host: " localhost ", wantHost: "localhost", wantErr: false},
{name: "explicit multi host normalized", explicit: true, host: " [::1] , 127.0.0.1 ", wantHost: "::1,127.0.0.1", wantErr: false},
}
for _, tt := range tests {