From 03d694caeb86d1399d2faab139a234b01c095956 Mon Sep 17 00:00:00 2001 From: Garo Brik Date: Mon, 18 Jan 2021 13:15:39 -0800 Subject: [PATCH] add an optional upload argument for an associated index ID --- upload.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/upload.go b/upload.go index 7a60c92..e91d8b9 100644 --- a/upload.go +++ b/upload.go @@ -27,6 +27,7 @@ type UploadIndexOpts struct { Indexer string GitHubToken string File string + AssociatedIndexID *int MaxPayloadSizeBytes int MaxRetries int RetryInterval time.Duration @@ -91,6 +92,7 @@ func uploadIndex(opts UploadIndexOpts) (id int, err error) { root: opts.Root, indexer: opts.Indexer, gitHubToken: opts.GitHubToken, + associatedIndexID: opts.AssociatedIndexID, } if err := retry(func() (_ bool, err error) { @@ -139,6 +141,7 @@ func uploadMultipartIndex(opts UploadIndexOpts) (id int, err error) { gitHubToken: opts.GitHubToken, multiPart: true, numParts: len(files), + associatedIndexID: opts.AssociatedIndexID, } if err := retry(func() (bool, error) { return makeUploadRequest(setupArgs, nil, &id, opts.Logger) }); err != nil { @@ -235,6 +238,7 @@ type requestArgs struct { uploadID int index int done bool + associatedIndexID *int } // EncodeQuery constructs a query string from the args. @@ -250,6 +254,10 @@ func (args requestArgs) EncodeQuery() string { qs.SetOptionalInt("uploadId", args.uploadID) qs.SetOptionalBool("done", args.done) + if args.associatedIndexID != nil { + qs.SetInt("associatedIndexID", *args.associatedIndexID) + } + // Do not set an index of zero unless we're uploading a part if args.uploadID != 0 && !args.multiPart && !args.done { qs.SetInt("index", args.index)