-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (36 loc) · 930 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"fmt"
"os"
"plugin"
"github.com/akutz/gpd/dep"
"github.com/akutz/gpd/lib"
)
func main() {
if len(os.Args) == 1 {
fmt.Println("Yes, we have no bananas,")
fmt.Println("We have no bananas today.")
os.Exit(0)
}
pluginPath := os.Args[1]
if !fileExists(pluginPath) {
fmt.Fprintf(os.Stderr, "error: invalid plugin file: %s\n", pluginPath)
os.Exit(1)
}
// open the plug-in file, causing its package init function to run,
// thereby registering the module
if _, err := plugin.Open(pluginPath); err != nil {
fmt.Fprintf(os.Stderr, "error: failed to load plugin: %v\n", err)
}
// Instantiate a copy of the module registered by the plug-in.
modGo := lib.NewModule("mod_go")
// Initialize mod_go
modGo.Init(context.Background(), dep.Config{})
}
func fileExists(filePath string) bool {
if _, err := os.Stat(filePath); !os.IsNotExist(err) {
return true
}
return false
}