[Advice needed] How to vendor common dependencies for plugins

142 views
Skip to first unread message

Jay Guo

unread,
Mar 8, 2018, 1:03:37 AM3/8/18
to golang-nuts
Golang gurus,

I'm currently trying to modularize my project with the help of Golang plugin, and I come across this dependency vendoring dilemma.

Let's say we have a project layout:
  • Two different projects in separate repo: `Host` and `Guest`
  • `Host` depends on package `pkgA`
  • `Guest` depends on package `pkgA` too
  • `Guest` is compiled as plugin, and loaded by `Host`
  • `pkgA` is vendored into both `Host` and `Guest`
In this situation, `pkgA` would be loaded twice and independently, meaning there are two instance of the package in the program, one lives in `Guest` and one in `Host`. init() would be called twice as well

Particularly, I'm dealing with golang.org/x/net/trace package, which actually registers an endpoint /debug/requests. The second attempt would panic because of double-registration.

I'd appreciate any advice on how to manage common dependencies of plugin and main project, thank you!

- J

Michael Andersen

unread,
Mar 8, 2018, 6:36:37 PM3/8/18
to golang-nuts
I am interested in this problem too, especially dealing with golang.org/x/net/trace which is used by grpc which is used by multiple packages I import.

Jay Guo

unread,
Mar 11, 2018, 5:02:45 AM3/11/18
to golang-nuts
Bump.. any thoughts? Thanks!

- J

Matt Harden

unread,
Mar 18, 2018, 3:57:40 PM3/18/18
to Jay Guo, golang-nuts
Do you have to use plugins? I would avoid them whenever possible. What benefit do you expect to get from using them?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jay Guo

unread,
Mar 19, 2018, 2:45:24 AM3/19/18
to Matt Harden, golang-nuts
Hi Matt,

basically we need to be able to install some user plugins at runtime. I'm not sure Go `plugin` is avoidable in this case...

- J

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages