如何使用Go编写模块化(插件化)应用程序?

huangapple go评论84阅读模式
英文:

How to write modular (plug-in) applications with Go?

问题

我了解Go编程语言实际上不支持动态链接。这让我想知道,如果有人想要编写支持第三方(或其他贡献的)插件的应用程序,他们会怎么做?

似乎典型的回答是Go编译速度快,所以只需重新编译,但我觉得这对于系统管理员来说并不是很实用。例如,Apache Web服务器有大量可以轻松配置为加载(或不加载)的模块。

难道唯一的选择是使用套接字或其他进程间通信来实现插件吗?

英文:

I understand that the Go programming language doesn't really support dynamic linking. This makes me wonder, what would somebody do if they wanted to write an application that supported third party (or otherwise contributed) plug-ins?

It seems the typical response is that Go compiles quickly, so just recompile, but I don't find this all that practical for system administrators. The Apache web server for example, has an amazing number of modules that can be configured to be loaded (or not loaded) very easily.

Is the only option left to use sockets or other IPC for plugins?

答案1

得分: 3

我会做的是,通过管道设置一个API。然后告诉插件作者发布一个可以通过这个管道进行通信的exe文件。

这与Chrome今天的工作方式类似。

这是通过netchan实现的一种方法。

注意: netchan包已经被弃用,但是使用RPC over unix pipes的想法是一样的。

英文:

What I would do, is, set up an API through, say, channel over pipe. And tell the plugin author to issue an exe that communicate over this pipe.

This is similar to how Chrome works today.

This is a way to achieve that over netchan.

Note: the netchan pacakage is deprecated, but the idea is to use RPC over unix pipes.

huangapple
  • 本文由 发表于 2011年11月7日 11:47:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/8032523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定