Documentation
¶
Overview ¶
Package pluginunmarshal unmarshals Go plugins into structs.
Example ¶
package main import ( "fmt" "github.com/tcard/pluginunmarshal" ) func main() { // Assume pathToPlugin refers to a Go plugin file compiled from this code: // // package main // // var Hello = "Hello from a plugin!" // // func Add(a, b int) int { // return a + b // } // var v struct { Add func(a, b int) int MyHello string `plugin:"Hello"` Ignored bool `plugin:"-"` } err := pluginunmarshal.Open(pathToPlugin, &v) if err != nil { panic(err) } fmt.Println(v.Add(2, 3)) fmt.Println(v.MyHello) } var pathToPlugin string
Output: 5 Hello from a plugin!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open is a convenience function for calling "plugin".Open and then calling Unmarshal with the resulting plugin.
func Unmarshal ¶
Unmarshal stores exported values from a plugin into the struct pointed to by v.
By default, each exported field in the struct will be assigned to a package-level exported value in the plugin with the same name as the field.
The plugin value's type must be assignable to the field's type.
If the plugin value is variable, the field's type can also be a pointer to the variable's type; in that case, the field will point to the variable.
If no such value exists in the plugin, Unmarshal returns an error.
This behavior can be modified by a struct tag with key "plugin", as follows:
// Field is ignored by this package. Field int `plugin:"-"` // Field is mapped to the package-level value Other from the plugin. Field int `plugin:"Other"` // If a value named "Field" isn't exported from the plugin, the struct // field Field will be ignored instead of Unmarshal returning an error. Field int `plugin:",omitempty"`
See package-level examples.
Types ¶
This section is empty.