-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mateusz Gajewski
committed
Nov 12, 2016
1 parent
2c61402
commit 32a89ae
Showing
18 changed files
with
739 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
cli/internal/test_fixtures/generated/basic_plugin/plugin.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
package main | ||
|
||
// Autogenerated by github.com/wendigo/go-bind-plugin on 2016-11-12 19:45:36.989271091 +0100 CET, do not edit! | ||
// Command: go-bind-plugin -plugin-path ./internal/test_fixtures/generated/basic_plugin/plugin.so -plugin-package ./internal/test_fixtures/basic_plugin -output-name TestWrapper -output-path ./internal/test_fixtures/generated/basic_plugin/plugin.go -output-package main -sha256 -rebuild | ||
// | ||
// Plugin ./internal/test_fixtures/generated/basic_plugin/plugin.so info: | ||
// - package: github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin | ||
// - size: 2447824 bytes | ||
// - sha256: e3d68f431cbee5fd88dd41dca29d38f09c148d83ed668612a0e4813808280483 | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"os" | ||
"plugin" | ||
"reflect" | ||
"strings" | ||
) | ||
|
||
// TestWrapper wraps symbols (functions and variables) exported by plugin github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin | ||
// | ||
// See docs at https://godoc.org/github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin | ||
type TestWrapper struct { | ||
// Exported functions | ||
_NonReturningFunction func() | ||
_ReturningInt32 func() int32 | ||
_ReturningIntArray func() [3]int32 | ||
_ReturningStringSlice func() []string | ||
|
||
// Exported variables (public references) | ||
|
||
} | ||
|
||
// NonReturningFunction function was exported from plugin github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin symbol 'NonReturningFunction' | ||
// | ||
// See docs at https://godoc.org/github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin#NonReturningFunction | ||
func (p *TestWrapper) NonReturningFunction() { | ||
p._NonReturningFunction() | ||
} | ||
|
||
// ReturningInt32 function was exported from plugin github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin symbol 'ReturningInt32' | ||
// | ||
// See docs at https://godoc.org/github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin#ReturningInt32 | ||
func (p *TestWrapper) ReturningInt32() int32 { | ||
return p._ReturningInt32() | ||
} | ||
|
||
// ReturningIntArray function was exported from plugin github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin symbol 'ReturningIntArray' | ||
// | ||
// See docs at https://godoc.org/github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin#ReturningIntArray | ||
func (p *TestWrapper) ReturningIntArray() [3]int32 { | ||
return p._ReturningIntArray() | ||
} | ||
|
||
// ReturningStringSlice function was exported from plugin github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin symbol 'ReturningStringSlice' | ||
// | ||
// See docs at https://godoc.org/github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin#ReturningStringSlice | ||
func (p *TestWrapper) ReturningStringSlice() []string { | ||
return p._ReturningStringSlice() | ||
} | ||
|
||
// String returnes textual representation of the wrapper. It provides info on exported symbols and variables. | ||
func (p *TestWrapper) String() string { | ||
var lines []string | ||
lines = append(lines, "Struct TestWrapper:") | ||
lines = append(lines, "\t- Generated on: 2016-11-12 19:45:36.989271091 +0100 CET") | ||
lines = append(lines, "\t- Command: go-bind-plugin -plugin-path ./internal/test_fixtures/generated/basic_plugin/plugin.so -plugin-package ./internal/test_fixtures/basic_plugin -output-name TestWrapper -output-path ./internal/test_fixtures/generated/basic_plugin/plugin.go -output-package main -sha256 -rebuild") | ||
lines = append(lines, "\nPlugin info:") | ||
lines = append(lines, "\t- package: github.com/wendigo/go-bind-plugin/cli/internal/test_fixtures/basic_plugin") | ||
lines = append(lines, "\t- sha256 sum: e3d68f431cbee5fd88dd41dca29d38f09c148d83ed668612a0e4813808280483") | ||
lines = append(lines, "\t- size: 2447824 bytes") | ||
lines = append(lines, "\nExported functions (4):") | ||
lines = append(lines, "\t- NonReturningFunction func()") | ||
lines = append(lines, "\t- ReturningInt32 func() (int32)") | ||
lines = append(lines, "\t- ReturningIntArray func() ([3]int32)") | ||
lines = append(lines, "\t- ReturningStringSlice func() ([]string)") | ||
|
||
return strings.Join(lines, "\n") | ||
} | ||
|
||
// BindTestWrapper loads plugin from the given path and binds symbols (variables and functions) | ||
// to the TestWrapper struct. | ||
// When plugin is loaded sha256 checksum is computed and checked against precomputed once. On mismatch error is returned. | ||
func BindTestWrapper(path string) (*TestWrapper, error) { | ||
p, err := plugin.Open(path) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not open plugin: %s", err) | ||
} | ||
|
||
fileChecksum := func(path string) (string, error) { | ||
hasher := sha256.New() | ||
|
||
file, err := os.Open(path) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
|
||
if _, err := io.Copy(hasher, file); err != nil { | ||
return "", err | ||
} | ||
|
||
return hex.EncodeToString(hasher.Sum(nil)), nil | ||
} | ||
|
||
checksum, err := fileChecksum(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not calculate file %s checksum", path) | ||
} | ||
|
||
if checksum != "e3d68f431cbee5fd88dd41dca29d38f09c148d83ed668612a0e4813808280483" { | ||
return nil, fmt.Errorf("SHA256 checksum mismatch (expected: e3d68f431cbee5fd88dd41dca29d38f09c148d83ed668612a0e4813808280483, actual: %s)", checksum) | ||
} | ||
|
||
ret := new(TestWrapper) | ||
|
||
funcNonReturningFunction, err := p.Lookup("NonReturningFunction") | ||
if err != nil { | ||
return nil, fmt.Errorf("could not import function 'NonReturningFunction', symbol not found: %s", err) | ||
} | ||
|
||
if typed, ok := funcNonReturningFunction.(func()); ok { | ||
ret._NonReturningFunction = typed | ||
} else { | ||
return nil, fmt.Errorf("could not import function 'NonReturningFunction', incompatible types 'func()' and '%s'", reflect.TypeOf(funcNonReturningFunction)) | ||
} | ||
|
||
funcReturningInt32, err := p.Lookup("ReturningInt32") | ||
if err != nil { | ||
return nil, fmt.Errorf("could not import function 'ReturningInt32', symbol not found: %s", err) | ||
} | ||
|
||
if typed, ok := funcReturningInt32.(func() int32); ok { | ||
ret._ReturningInt32 = typed | ||
} else { | ||
return nil, fmt.Errorf("could not import function 'ReturningInt32', incompatible types 'func() (int32)' and '%s'", reflect.TypeOf(funcReturningInt32)) | ||
} | ||
|
||
funcReturningIntArray, err := p.Lookup("ReturningIntArray") | ||
if err != nil { | ||
return nil, fmt.Errorf("could not import function 'ReturningIntArray', symbol not found: %s", err) | ||
} | ||
|
||
if typed, ok := funcReturningIntArray.(func() [3]int32); ok { | ||
ret._ReturningIntArray = typed | ||
} else { | ||
return nil, fmt.Errorf("could not import function 'ReturningIntArray', incompatible types 'func() ([3]int32)' and '%s'", reflect.TypeOf(funcReturningIntArray)) | ||
} | ||
|
||
funcReturningStringSlice, err := p.Lookup("ReturningStringSlice") | ||
if err != nil { | ||
return nil, fmt.Errorf("could not import function 'ReturningStringSlice', symbol not found: %s", err) | ||
} | ||
|
||
if typed, ok := funcReturningStringSlice.(func() []string); ok { | ||
ret._ReturningStringSlice = typed | ||
} else { | ||
return nil, fmt.Errorf("could not import function 'ReturningStringSlice', incompatible types 'func() ([]string)' and '%s'", reflect.TypeOf(funcReturningStringSlice)) | ||
} | ||
|
||
return ret, nil | ||
} | ||
|
||
|
||
func main() { | ||
pl, err := BindTestWrapper("./internal/test_fixtures/generated/basic_plugin/plugin.so") | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(pl.ReturningIntArray()) | ||
} |
Binary file not shown.
Oops, something went wrong.