dsfs64664 2013-12-19 13:27
浏览 106
已采纳

是否可以从Python提供Go接口的实现?

I have a Go lib which does concurrent processing on variable data, I have a (simplified) interface:

type Handler interface {
    Accepts(id []byte) bool
    ProcessUnit(u []byte) []byte
}

Currently, library end-developer (user) might write go code which implements this interface and a library can work on end-developer data structures.

Now the real question: (lets skip overhead), is it possible to provide implementation of that interface written in another language (with Python in mind)? My intention is to provide a "Plugin API" so anyone can add handlers, written in eg: Python (or possibly other languages)

I already have a working implementation which uses zeromq to pass data around go<->python, but this feels "non-natural". The utopia I want to achieve is that an lib user places plugins.py file in predefined location, and go can load plugins automatically on startup, is it possible or I'm looking in wrong direction?

  • 写回答

1条回答 默认 最新

  • dongneng5383 2013-12-19 13:57
    关注

    Go has no dynamic loading of modules (at least in zero and first order approximation), so no, you cannot just place a plugins.py somewhere and have a Go programm load and use it, at least not from Go itself...

    ...But you might be able to use go-python https://github.com/sbinet/go-python or goPy https://github.com/qur/gopy which should allow you to run the python interpreter from Go and the python interpreter can do dynamic module loads. This will get a bit ugly with some forth and back between Go and Python but should be doable.

    Passing data around (either zeromq or maybe direct via package net/rpc) doesn't seem "non-natural" to me...

    (Sidenote: If somebody can write proper Python code and gets some help understanding pointers he should be able to write Go code in a few days.)

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集