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.
相关问题
- Golang mongodb aggregation
- Stop child process when parent process stops
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- Mathjax not rendering TEX formulas dynamically fro
相关文章
- Angular Material Stepper causes mat-formfield to v
- Can I run a single test in a suite?
- How to check if a request was cancelled
- Is it possible to implement an interface with unex
- unable to install packages(“caret”) completely in
- How to access value of first index of array in Go
- Embedded Interface
- How to represent an array with mixed types
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.
Just do these,create a codegen that reads the configuration, generates a basic go file with the packages loaded in order and then execute that, compile languages won't nor provide dynamic loading, even dart suffers in a way,simple just read your configuration file then create a temporary file with the necessary codes to load up and communicate with sockets or http
I think what you are looking for is the special function
init
if you add a
inside a package it will run it the first time the package is imported. This happens only in the same binary. As other have already said go does not support dynamically loaded libraries.
There is support for this now as of go 1.8
https://golang.org/pkg/plugin/
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.