You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
10
10
**go-bind-plugin** generates neat API around symbols exported by a plugin built with `go build -buildmode=plugin` in upcoming go 1.8. [plugin.Plugin](https://tip.golang.org/pkg/plugin/#Plugin) holds information about exported symbols as map[string]interface{}. go-bind-plugins uses reflection to find out actual types of symbols and generates typed API for a provided plugin with additional functionalities (like dereferencing exported variables and checking sha256 sum). Basic usage does not require plugin sources as wrapper can be generated using only `.so` file.
11
11
12
-
For example if plugin exports `AddTwoInts(a, b int) int` function instead of using [Plugin.Lookup](https://tip.golang.org/pkg/plugin/#Plugin.Lookup) directly:
12
+
For example if plugin exports `AddTwoInts(a, b int) int` function and `BuildVersion string` variable instead of using [Plugin.Lookup](https://tip.golang.org/pkg/plugin/#Plugin.Lookup) directly:
13
13
14
14
```
15
15
plug, err := plugin.Open("plugin.so")
@@ -25,6 +25,19 @@ if err != nil {
25
25
26
26
if typed, ok := symbol.(func(int, int) int); ok {
27
27
result := typed(10, 20)
28
+
} else {
29
+
panic("AddTwoInts has different type than exported by plugin")
30
+
}
31
+
32
+
symbol, err := plug.Lookup("BuildVersion")
33
+
if err != nil {
34
+
panic(err)
35
+
}
36
+
37
+
if typed, ok := symbol.(*string); ok {
38
+
fmt.Println(*typed)
39
+
} else {
40
+
panic("BuildVersion is not a string reference")
28
41
}
29
42
```
30
43
@@ -38,6 +51,7 @@ if err != nil {
38
51
}
39
52
40
53
result := plug.AddTwoInts(10, 20)
54
+
fmt.Println(plug.BuildVersion) // or fmt.Println(*plug.BuildVersion) if -dereference-vars is not used
41
55
```
42
56
43
57
`BingPluginAPI()` will ensure that plugin exports `AddTwoInts` functions and its type is `func(int, int) int`.
@@ -47,11 +61,8 @@ result := plug.AddTwoInts(10, 20)
47
61
```
48
62
go get -u github.com/wendigo/go-bind-plugin
0 commit comments