mirror of
https://github.com/google/ax.git
synced 2026-10-02 03:14:37 +08:00
Introduce openConn
This commit is contained in:
+2
-5
@@ -7,8 +7,6 @@ import (
|
||||
|
||||
"github.com/google/gar/proto"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -32,10 +30,9 @@ func init() {
|
||||
func runInspect(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Inspecting session: %s\n", inspectSessionID)
|
||||
|
||||
// Connect to gRPC server
|
||||
conn, err := grpc.NewClient(inspectServerAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
conn, err := openConn(inspectServerAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to server: %w", err)
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -14,3 +17,11 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func openConn(server string) (*grpc.ClientConn, error) {
|
||||
conn, err := grpc.NewClient(server, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to connect to server: %w", err)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
+2
-5
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
"github.com/google/gar/proto"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -44,10 +42,9 @@ func runRegister(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf(" Description: %s\n", registerAgentDesc)
|
||||
}
|
||||
|
||||
// Connect to gRPC server
|
||||
conn, err := grpc.NewClient(registerServerAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
conn, err := openConn(inspectServerAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to server: %w", err)
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
||||
+2
-8
@@ -11,8 +11,6 @@ import (
|
||||
"github.com/google/gar/proto"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -73,15 +71,13 @@ func runTrigger(cmd *cobra.Command, args []string) error {
|
||||
cancel()
|
||||
}()
|
||||
|
||||
// Connect to gRPC server
|
||||
conn, err := grpc.NewClient(triggerServerAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
conn, err := openConn(inspectServerAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to server: %w", err)
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := proto.NewGARServiceClient(conn)
|
||||
|
||||
stream, err := client.TriggerSession(ctx, &proto.TriggerSessionRequest{
|
||||
SessionId: triggerSessionID,
|
||||
Inputs: inputs,
|
||||
@@ -105,7 +101,5 @@ func runTrigger(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("[%s] %s\n", resp.State, resp.Output.Data)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Session completed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user