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

允许使用第三方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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口