Skip to content

Instantly share code, notes, and snippets.



Last active Mar 5, 2019
What would you like to do?
Using Golang plugin
package main
import (
func main() {
// Glob - Gets the plugin to be loaded
plugins, err := filepath.Glob("")
if err != nil {
// Open - Loads the plugin
fmt.Printf("Loading plugin %s", plugins[0])
p, err := plugin.Open(plugins[0])
if err != nil {
// Lookup - Searches for a symbol name in the plugin
symbol, err := p.Lookup("Add")
if err != nil {
// symbol - Checks the function signature
addFunc, ok := symbol.(func(int, int) int)
if !ok {
panic("Plugin has no 'Add(int)int' function")
// Uses the function to return results
addition := addFunc(3, 4)
fmt.Printf("\nAddition is:%d", addition)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.