ELI5 Go Plugins?

xuanbao · · 499 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I tried to couple of articles and also official <a href="https://golang.org/pkg/plugin/" rel="nofollow">page</a> but I still don&#39;t get it. Can anyone do an ELI5? </p> <p>I am coming from Python, so something comparable to Python, if exists, would be nice.</p> <hr/>**评论:**<br/><br/>niosop: <pre><p>It lets you load and execute code at runtime. I guess an example might be best. Say you have a metrics collection program written in Go. It knows how to use SNMP to collect metrics from SNMP capable devices. If you wanted to be able to add the ability to use SSH to connect to a device and get some data, then you&#39;d need to add that to the code and recompile it. Anyone else who wanted to use your SSH code would either have to use your forked version, or download and apply your patches to the base distribution.</p> <p>A better way would be to use a plugin system. The base collector program would define the function signature required for any collector, and people could write plugins that do whatever they want. Then they could just drop the plugin into a directory, modify a config file to tell it to use the plugin, and the base program could read a list of plugins from the config file, load those plugins, then execute the collection function for each plugin. People would no longer have to recompile or use a forked version, they could just download your plugin.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

499 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传