Pingo Go 的插件化开发开源项目

我要开发同款
匿名用户2015年04月28日
77阅读

技术信息

开源地址
https://github.com/google/gsa-admin-toolkit
授权协议
MIT

作品详情

Pigo是一个用来为Go程序编写插件的简单独立库,因为Go本身是静态链接的,因此所有插件都以外部进程方式存在。Pigo旨在简化标准RPC包,支持TCP和Uix套接字作为通讯协议。当前还不支持远程插件,如果有需要,远程插件很快会提供。

使用Pigo创建一个插件非常简单,首先新建目录,如"plugis/hello-world",然后在该目录下编写mai.go:

// Always create a ew biarypackage maiimport "github.com/dullgiulio/pigo"// Create a object to be exportedtype MyPlugi struct{}// Exported method, with a RPC sigaturefuc (p *MyPlugi) SayHello(ame strig, msg *strig) error {    *msg = "Hello, " + ame    retur il}fuc mai() {    plugi := &MyPlugi{}    // Register the objects to be exported    pigo.Register(plugi)    // Ru the mai evets hadler    pigo.Ru()}

编译:

$ cd plugis/hello-world$ go build

接下来就可以调用该插件:

package maiimport (    "log"    "github.com/dullgiulio/pigo")fuc mai() {    // Make a ew plugi from the executable we created. Coect to it via TCP    p := pigo.NewPlugi("tcp", "plugis/hello-world/hello-world")    // Actually start the plugi    p.Start()    // Remember to stop the plugi whe doe usig it    defer p.Stop()    var resp strig    // Call a fuctio from the object we created previously    if err := p.Call("MyPlugi.SayHello", "Go developer", &resp); err != il {        log.Prit(err)    } else {        log.Prit(resp)    }}

功能介绍

Pingo 是一个用来为 Go 程序编写插件的简单独立库,因为 Go 本身是静态链接的,因此所有插件都以外部进程方式存在。Pingo 旨在简化标准 RPC 包,支持 TCP 和 Unix 套接字...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论