For normal GO code, documentation is done as described here by:
to document a type, variable, constant, function, or even a package,
write a regular comment directly preceding its declaration, with no
intervening blank line. Godoc will then present that comment as text
alongside the item it documents.
Example:
// Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string.
// It returns the number of bytes written and any write error encountered.
func Fprint(w io.Writer, a ...interface{}) (n int, err error) { }
I wrote the below code using plugin:
//file: ./plugin/plugin.go
package main
import "fmt"
var V int
func F() {
fmt.Printf("Hello, number %d\n", V)
}
// A test plugin function to Return double the entery
func Fx(x int) int {
return x * 2
}
// Compile as: $ go build -buildmode=plugin
Complied is a s a plugin, and called it from the main code:
// file main.go
package main
import (
"plugin"
)
func main() {
p, _ := plugin.Open("./plugin/plugin.so") // use rela path with code runner: /Users/hasan/goApps/mod/plugin/plugin.so
v, _ := p.Lookup("V")
f, _ := p.Lookup("F")
fx, _ := p.Lookup("Fx")
*v.(*int) = 7 // .(symbol signature) => (*int)
f.(func())() // .(symbol signature) => func() { }
num := fx.(func(int) int)(3). // .(symbol signature) => func(int) int { }
println(num)
}
// Run as $ go run .
The plugin worked as expected, and showed below output:
hasan@Hasans-MacBook-Air goApps % go run .
Hello, number 7
6
But documentation did not show up, and once I hovered in my IDE (VS Code) above the fx
in every line it appeared in at main.go
nothing show up.