douzuita7325 2016-03-29 08:58
浏览 14
已采纳

如何在不破坏客户端代码的情况下拆分大型程序包?

Let's say I have a library package called foobar.

Over time it became big and heavy.

Fortunately it's separable, I managed to split its functionality into two separate packages foo and bar -- most clients will only need to use one or the other.

Since my library is already in use by many clients, for compatibility I still want to maintain a foobar package as a proxy to the current functionality found in both foo and bar.

How does one achieve this in Go ?

One way that comes to mind is to create aliases in foobar for each struct/function in foo and bar. So if foo defines F() and bar defines B(), I would have in foobar:

var (
  F = foo.F
  B = bar.B
)

But I am hoping for an easier/cleaner way.

  • 写回答

1条回答 默认 最新

  • doucan4815 2016-03-29 10:15
    关注

    Creating an alias package is the only way. But your attempt probably won't work: It works only for functions and variables and consts but not for types. For types you have to duplicate the type in foobar.

    I wouldn't do this. Just have foobar around in version 1 and start anew with foo and bar (maybe directly in version 2).

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

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的