Go Integration

Orchestrate VCursor video generation from your high-performance Go services and microservices.

Using os/exec

The os/exec package provides a robust way to wrap the VCursor CLI. Use the --json flag to retrieve structured, machine-readable output.

main.go
package main

import (
	"encoding/json"
	"fmt"
	"os/exec"
)

// Response structure matches CLI --json output
type VCursorResponse struct {
	Code int `json:"code"`
	Data struct {
		Status   string `json:"status"`
		Products struct {
			URL string `json:"url"`
		} `json:"products"`
	} `json:"data"`
}

func GenerateVideo(prompt string) (string, error) {
	// Execute vcursor pointing to json output
	cmd := exec.Command("vcursor", prompt, "--json")
	output, err := cmd.Output()
	if err != nil {
		return "", fmt.Errorf("execution error: %v", err)
	}

	var resp VCursorResponse
	if err := json.Unmarshal(output, &resp); err != nil {
		return "", fmt.Errorf("parse error: %v", err)
	}

	if resp.Data.Status != "completed" {
		return "", fmt.Errorf("task failed or incomplete")
	}

	return resp.Data.Products.URL, nil
}

func main() {
	url, err := GenerateVideo("a calm ocean at sunset")
	if err != nil {
		panic(err)
	}
	fmt.Println("Video URL:", url)
}

Best Practices

Environment Variables

Pass the API key via the process environment instead of hardcoding it.

cmd.Env = append(os.Environ(), "VCURSOR_API_KEY=...")

Error Handling

Always check both the command exit code and the JSON status field, as generation failures might return a clean exit code but a "failed" status in the data.