From 897aee898b649e5269a4a28f439e89a6a70e3576 Mon Sep 17 00:00:00 2001 From: seanavery Date: Tue, 1 Oct 2024 16:16:08 -0400 Subject: [PATCH] Add env var checkers --- examples/save_client.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/save_client.go b/examples/save_client.go index eed8211..3cb77be 100644 --- a/examples/save_client.go +++ b/examples/save_client.go @@ -2,7 +2,7 @@ This example domenstrates calling async save command on video-store resource. To setup: - You need to have a robot running with video-store component. - Ensure you have a .env file with the necessary credentials and secrets. -- run example script `go run save_client.go` +- Run example script `go run save_client.go` */ package main @@ -25,12 +25,14 @@ func main() { err := godotenv.Load() if err != nil { - logger.Fatalf("Error loading .env file") + logger.Fatal("Please make sure you add a .env file with the necessary credentials and secrets.") } - robotAddress := os.Getenv("ROBOT_ADDRESS") apiKeyID := os.Getenv("API_KEY_ID") apiKey := os.Getenv("API_KEY") + if robotAddress == "" || apiKeyID == "" || apiKey == "" { + logger.Fatal("Missing required environment variables: ROBOT_ADDRESS, API_KEY_ID, or API_KEY.") + } machine, err := client.New( context.Background(), @@ -46,7 +48,6 @@ func main() { if err != nil { logger.Fatal(err) } - defer machine.Close(context.Background()) logger.Info("Resources:") logger.Info(machine.ResourceNames()) @@ -63,6 +64,7 @@ func main() { } logger.Infof("video-store Properties return value: %+v", videoStoreReturnValue) + // Save clip of random duration every 30 seconds for { now := time.Now() rand.Seed(uint64(time.Now().UnixNano()))