Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 915 Bytes

README.md

File metadata and controls

35 lines (29 loc) · 915 Bytes

pluginunmarshal Build Status GoDoc

Package pluginunmarshal unmarshals Go plugins into structs.

// 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)
// Output:
// 5
// Hello from a plugin!

See the docs for more.