Author: techfox9

Building and using a plugin in Go / Golang

Wednesday, January 15th, 2020 @ 6:25 pm

From https://medium.com/quick-code/write-a-web-service-with-go-plug-ins-c0472e0645e6

The plugin module (pluginex1.go):

[java]

package main

import “fmt”

func Talk() {
fmt.Println(“Hello From Plugin !”)
}

[/java]

Build the plugin module:

[java]

# go build -buildmode=plugin -o pluginex1.so pluginex1.go

[/java]

Invoke the plugin module (pluginex1main.go):

[java]

package main

import(
“os”
“fmt”
“plugin”
)

func main() {
plugin, err := plugin.Open(“pluginex1.so”)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
sym, err := plugin.Lookup(“Talk”) // reflection
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
sym.(func())()
}

[/java]

. . .

GoLang


 


Comments are closed.