package main import ( "context" "fmt" "log" "os" "time" "gitea.maximumdirect.net/eric/distributor/pkg/upload" ) func main() { token := os.Getenv("DISTRIBUTOR_EXAMPLE_UPLOAD_TOKEN") if token == "" { log.Fatal("set DISTRIBUTOR_EXAMPLE_UPLOAD_TOKEN before running this example") } endpoint := os.Getenv("DISTRIBUTOR_EXAMPLE_UPLOAD_ENDPOINT") if endpoint == "" { endpoint = "http://127.0.0.1:8080" } bundleRoot := "examples/source-bundle" if len(os.Args) > 1 { bundleRoot = os.Args[1] } pipelineID := os.Getenv("DISTRIBUTOR_EXAMPLE_UPLOAD_PIPELINE_ID") if pipelineID == "" { pipelineID = "example-http-upload" } if len(os.Args) > 2 { pipelineID = os.Args[2] } idempotencyKey := os.Getenv("DISTRIBUTOR_EXAMPLE_UPLOAD_IDEMPOTENCY_KEY") client, err := upload.NewClient(upload.ClientOptions{ Endpoint: endpoint, Token: token, }) if err != nil { log.Fatal(err) } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() opts := upload.UploadBundleOptions{ PipelineID: pipelineID, Root: bundleRoot, } if idempotencyKey != "" { opts.IdempotencyKey = idempotencyKey } result, err := client.UploadBundle(ctx, opts) if err != nil { log.Fatal(err) } fmt.Printf("accepted run %s with status %s\n", result.RunID, result.Status) }