package gatewayrpc import ( "fmt" "strings" "google.golang.org/grpc" "github.com/samcharles93/archie-core/internal/domain/presence" "github.com/samcharles93/archie-core/internal/infrastructure/rpctls" ) // Dial returns a Gateway chat client for target, authenticated by id. The // cleanup closes the connection. func Dial(target string, id *rpctls.Identity, options ...grpc.DialOption) (*Client, func(), error) { target = strings.TrimSpace(target) if target == "" { return nil, nil, fmt.Errorf("gateway target is required") } creds, err := id.DialOption(target, presence.Gateway) if err != nil { return nil, nil, fmt.Errorf("gateway: %w", err) } opts := []grpc.DialOption{ creds, grpc.WithUnaryInterceptor(unaryPrincipal), grpc.WithStreamInterceptor(streamPrincipal), } conn, err := grpc.NewClient(target, append(opts, options...)...) if err != nil { return nil, nil, fmt.Errorf("create gateway client: %w", err) } return NewClient(conn), func() { _ = conn.Close() }, nil }