The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
zarte

golang 程序如何实现插件功能

  •  
  •   zarte · Jun 27, 2019 · 4880 views
    This topic created in 2598 days ago, the information mentioned may be changed or developed.

    场景如下:
    已经编译好主程序。main.exe. 解析不同文件的。
    后来有了新格式文件,编写了新的解析插件:plug1.exe.main.exe 根据获取的参数调用 plug1.exe 解析。

    上面这样是目前想到的,有常规合理的解决办法吗?

    10 replies    2019-06-28 04:11:31 +08:00
    index90
        1
    index90  
       Jun 27, 2019   ❤️ 1
    你想问 Go 能不能使用动态链接库吧?据我所知貌似不能。

    但应该有办法,例如 plug1.exe 实现 unix socket 接口,然后 main.exe 去调。
    z0ne
        2
    z0ne  
       Jun 27, 2019 via iPhone   ❤️ 2
    Go 是可以编译和调用链接库的 动态 /静态
    但是只能在 unix 系上用,比如 linux 和 macOS,可以编译成.so 文件,不能编译成 dll

    go build -buildmode=plugin plugin.go

    具体代码可以搜索,很多参考资料
    zarte
        3
    zarte  
    OP
       Jun 27, 2019
    @z0ne 谢谢
    misaka19000
        4
    misaka19000  
       Jun 27, 2019
    提供一个思路,用 lua 来实现解析的操作
    zarte
        5
    zarte  
    OP
       Jun 27, 2019
    @z0ne 以后有没有可能支持 dll ?
    zarte
        6
    zarte  
    OP
       Jun 27, 2019
    @misaka19000 那样又多了一个技术栈了
    zarte
        7
    zarte  
    OP
       Jun 27, 2019
    @misaka19000 不过比我想的方法好点
    janxin
        8
    janxin  
       Jun 27, 2019
    hashicorp/go-plugin 可以看一下

    Go 暂时没有后续支持动态链接库,最好也不要用这种方式。
    dbskcnc
        9
    dbskcnc  
       Jun 27, 2019
    Mitt
        10
    Mitt  
       Jun 28, 2019 via iPhone
    go build -buildmode=c-shared
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1175 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:40 · PVG 01:40 · LAX 10:40 · JFK 13:40
    ♥ Do have faith in what you're doing.