How to make Go web app plugin?

Hi all,

I’ve been thinking of a way to implement plugin ability for a Go web app, but got nothing out of my mind.

Any suggestions about how it is generally constructed and where to put hooks?

Thanks!

What do you consider a “plugin” to be?

How does it differ from traditional middleware that modifies the request/response - e.g. something that accepts a http.Handler and returns one - func (http.Handler) http.Handler that wraps middleware/the endpoint handler is pretty common.

You can wrap them per-route with http.Handle("/route", YourMiddleware(YourHandler)) or you can wrap a http.ServeMux itself (since it implements http.Handler). Libs like https://github.com/justinas/alice provide a way to chain middleware in a reusable manner.

Are you thinking of a different approach? Would your approach be compatible with existing std. lib. interfaces?

1 Like

For traditional plugins, take a look at github. com/natefinch/pie - if you can sort out the interface you need, that’s an easy and clean way to implement plugins.

1 Like

I’m assuming when you say plugin system you mean something that allows you to enable/disable 3rd party functionality on the fly. Yeah this seems like a tough problem to solve with a language like Go. The only two solutions I can think of are:

  1. Communicating with other applications over sockets.
  2. Generating source code, then rebuilding and restarting the application.
1 Like

Thank you all for replies!

I’ve found following two plugin systems that are interested me, which I can be inspired of:

So like @evantbyrne mentions, the first one is let my web app talks to 3rd-party web services, and second one is directly add source code by convention.

1 Like

Didn’t Go 1.5 introduce support for dynamic loading of shared objects? I’ve been meaning to take a look at it from the point of view of this particular problem, but haven’t yet.

Anyone?

I don’t believe that aspect has been implemented yet. Only being able to build C libraries with exported functions, and dynamic objects. But not the ability to dynamically load within a running Go application.

Right. I was remembering something mentioned in the design document, but wasn’t implemented for Go 1.5.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.