Hi everyone!
Being new to Go I'm looking into plugins https://golang.org/pkg/plugin/. I'd like to be able to dynamically load libs during runtime, plugin seems to be working, exactly what I need.
Since documentation around it looks scarce, at least regarding best practices, I wanted to ask here if anyone could share some best practices for building applications using plugin.
Another important aspect of interest is debugging. I have Go Land, love all things JetBrains pretty much, but how do you actually debug plugins once they are built as *.so files?
Thanks in advance!
评论:
callcifer:
pr0v4:Delve (the debugger Goland uses) doesn't support plugins yet as it depends on missing debug information that Go upstream needs to fix first.
widdma:Ok, that makes sense. Thanks!
pr0v4:You could take a look at other users on GoDoc.
That said, in general I've seen the the tendency in the Go community is to statically compile everything, even if you have some kind of plugin architecture internally. Telegraf is a good example of this pattern.
Plugin libraries may be nice for some use cases, but static builds are very convenient for distribution/deployment.
Perhaps folks here will be able to give better advice if you describe the problem you're trying to solve with plugin.
lluad:Telegraf is a solid example, thanks for sharing. It's on track of what we are trying to build.
The idea is to have a binary that would connect to the server and download plugins that it needs. Thus not deploying 15 plugins everywhere if only 3 are needed for example. And as with Telegraf to have a minimal memory footprint.
pr0v4:I think best practice around it is probably not to use it in production, not quite yet. It's almost there, at least on Linux, but not quite.
For dynamically loaded - rather than embedded at compile time - plugins I'd look at Hashicorp's go-plugin as an alternative, one that runs plugins out-of-process. It's grpc-based, so the plugins don't even need to be written in Go. Though if you're looking to minimize footprint that's probably the wrong direction.
upboatact:Can you note what's missing to be "production" ready? I really need it to have footprint as small as possible and performance is really important. Plugins will and can be written in GO, that's not a problem.
pr0v4:Admittedly just nitpicking here, but it's so weird to me: you wrote the name of the language correctly in your title and than you capitalized it in the body of your post. Why?
If it's to trigger people with OCD, well played :)
Thanks, I've edited that one :). Wasn't thinking about those details I guess.
