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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码