dongpu1881
2019-02-21 09:41
浏览 102
已采纳

允许使用第三方API从Golang的REST端点下载文件

This might sound odd but I am developing an endpoint(REST) that allows users to download the file(may be a zip). So I am hitting an 3rd party API to get the file and then I have to pass that to end users.

I can't expose 3rd party APIs. I am quite new to Golang and REST APIs as well. I can explore the concept but anyone has any idea, what is the best way to allow download of file from your REST endpoint which is actually coming from 3rd party.

I know this is very bad way to ask question but I have no idea what should I explore or read any blog which gives me this idea.

I am not looking for code, but more of an idea.

图片转代码服务由CSDN问答提供 功能建议

这听起来可能很奇怪,但我正在开发一个允许用户下载文件的终结点(REST)(可能是 压缩)。 所以我要通过第三方API获取文件,然后将其传递给最终用户。

我无法公开第三方API。 我对Golang和REST API也很陌生。 我可以探讨这个概念,但是任何人都知道,允许从REST端点下载文件的最佳方法是什么,而这实际上是来自第三方的。

我知道这很不好 提出问题的方式,但我不知道该探索或阅读任何使我有这个主意的博客。

我不是在寻找代码,而是在寻找主意。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyou7072 2019-02-21 10:57
    已采纳

    Golang has the abstraction of io.Reader which encapsulates almost anything that can be read in binary format.
    Usually if you have a file coming from a 3rd party API, you would have at least one way to build an io.Reader from that file, whether it's an HTTP request, gRPC, or local file.

    If you have your io.Reader, then definitely the requesting party would provide an io.Writer to allow you to write the response they are requesting. After this point all you have to do is bridge the io.Reader and io.Writer to copy on the fly the file from the 3rd party API to the requesting party using io.Copy or io.CopyN for example.

    打赏 评论

相关推荐 更多相似问题