Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load package dynamically

Is it possible to load a specific package during runtime? I want to have a kind of plugins where each one has the same functions than the others but with different behaviour, and depending on the configuration file, load one or other.

like image 565
Pepeluis Avatar asked Jul 08 '14 20:07

Pepeluis


People also ask

What is meant by dynamic loads?

Also known as a 'live load,' a dynamic load is one that changes in direction, position and magnitude, creating varied forces on a structure. This is different from a static load, which is constant and steady and produces a single response.

What is dynamic loading function?

Dynamic loading is a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.

What are dynamic loaded modules?

Dynamic Load Modules. Dynamic load modules provide the following functions: Load, refresh, and delete installation load modules, which are not part of the IBM® base JES2 code, after JES2 initialization processing. The dynamic table pairs and exit routine addresses are updated as needed.


3 Answers

No, Go doesn't support dynamically loaded libraries.

Your best bet is to start the plugin as its own executable and communicate with it through sockets or via stdin/stdout.

2017 update

This answer is no longer true, Go now supports plugins (for Linux and MacOS only as of June 2021)

like image 77
OneOfOne Avatar answered Oct 17 '22 16:10

OneOfOne


There is support for this now as of go 1.8

https://golang.org/pkg/plugin/

like image 42
thomasmeadows Avatar answered Oct 17 '22 15:10

thomasmeadows


You might consider executing the ‘plugin’ packages at runtime, by writing out a new program (say, to a temp directory) and executing via exec.Command, something along the lines of exec.Command("go", "run", files…).Run()

You’ll see some similar code here.

like image 18
Matt Sherman Avatar answered Oct 17 '22 15:10

Matt Sherman