英文:
gcs bucket how to get objects using filters [golang]
问题
有没有一种方法可以获取以特定条件开头和结尾的对象列表呢?
例如:
a/b/c/id1.json
a/b/c/id2.json
a/b/c/id3.json
a/c/id1.json
我们想要查询:
前缀: "a/",
结束位置: "id1.json"
期望的输出应该是:
a/b/c/id1.json
我们想要过滤掉其他选项,但我们不知道b
文件夹的名称是什么。
所以:
a
始终是a
b
是随机唯一的字符串
c
始终是c
我们总是想要特定的json文件。
我正在尝试使用以下代码实现:
query := &storage.Query{
Prefix: "a/",
//StartOffset: "",
EndOffset: "id1.json",
//Delimiter:
}
query.SetAttrSelection([]string{"Name"})
或者
Prefix: "c/id1.json",
Delimiter: "/",
IncludeTrailingDelimiter: true,
但是由于某种原因,我得到了所有这些文件的返回结果。
当然,我希望尽可能地限制结果以提高性能。
也许有办法在Prefix
定义中使用一些正则表达式?像a/*/c/id1.json
这样的。
谢谢。
英文:
Is there a way to get list of objects which starts and ends with specific criteria
as example:
a/b/c/id1.json
a/b/c/id2.json
a/b/c/id3.json
a/c/id1.json
and we wanna query for
Prefix: "a/",
EndOffset: "id1.json"
expected output should be:
a/b/c/id1.json
and we wanna filter out other options and we don't know what the b
folder name would be.
So:
a
is always a
b
is random uniq string
c
is always c
and we always want the specific json.
As i am tying to achieve this with:
query := &storage.Query{
Prefix: "a/",
//StartOffset: "",
EndOffset: "id1.json",
//Delimiter:
}
query.SetAttrSelection([]string{"Name"})
or
Prefix: "c/id1.json",
Delimiter: "/",
IncludeTrailingDelimiter: true,
and for some reason i am getting in return all of those files.
And of course i would like to limit the results as much as possible for better performances.
Maybe there is a way to use some regex in Prefix
definition ?
like a/*/c/id1.json
Thanks
----------------------- ========= Edited ========= -----------------------
Please note that this is already implemented by me storage_list_files_with_prefix-go and do not work as i would like to have it. So the main question is HOWTO make this filtering working with the example I am showing.
答案1
得分: 1
关键要点:
- 云存储桶没有目录。
- 命名空间是扁平的。
- 对象名称只是字符串。
- 斜杠
/
字符通常用于文件系统中分隔目录名称,但在云存储桶对象名称中只是一个字符。斜杠没有特殊意义,但可以用作分隔符。 - 您可以指定前缀和分隔符来减少返回的对象列表。
- 云存储不支持正则表达式。
- 星号
*
是一个字符,而不是通配符。
总结:
- 您必须在代码中实现额外的过滤。
英文:
Key points:
- Cloud Storage Buckets do not have directories.
- The namespace is flat.
- Object names are just strings.
- The slash
/
character which is often used to separate directory names in file systems is just a character in an Bucket object name. The slash has no significance but can be used as a delimiter. - You can specify a prefix and a delimiter to reduce the returned object list.
- Cloud Storage does not support regex expressions.
- The asterisk
*
is a character and not a wildcard.
Summary:
- You must implement additional filtering in your code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论