Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing S3 URI into bucket and key in Go [closed]

There doesn't seem to be a function in the official AWS Go SDK that'll parse an s3:// style URI-like string (i.e. s3://mybucket/some/place/on/there.gz) and provide things like the bucket and key. The Java SDK has such a function. Am I missing an obvious reason why the Go SDK does not?

This question is about maintaining compatibility. An SDK function provides a clear authority on how to properly parse S3 addresses and deters worry over subtle cases that url.Parse() and ilk may miss.

like image 209
Allen Luce Avatar asked Dec 24 '22 16:12

Allen Luce


1 Answers

Though only the AWS devs can answer the actual question (why isn't this included in the SDK), there is the simple answer: S3 URLs are URLs, and you can use net/url to parse them:

u,_ := url.Parse("s3://mybucket/some/place/on/there.gz")
fmt.Printf("proto: %q, bucket: %q, key: %q", u.Scheme, u.Host, u.Path)

Playground here

like image 195
Adrian Avatar answered Jan 05 '23 22:01

Adrian