-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (53 loc) · 1.63 KB
/
Copy pathmain.go
File metadata and controls
68 lines (53 loc) · 1.63 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"log"
"github.com/dkiser/go-plugin-example/plugin"
)
func playWithGreeters() {
// Grab a new manager for dealing with "greeter" type plugins
greeters := plugin.NewManager("greeter", "greeter-*", "./plugins/built", &plugin.GreeterPlugin{})
defer greeters.Dispose()
// Initialize greeters manager
err := greeters.Init()
if err != nil {
log.Fatal(err.Error())
}
// Launch all greeters binaries
greeters.Launch()
// Lets see what all the greeters say when you say "sup" to them
for _, pluginName := range []string{"foo", "hello"} {
// grab a plugin by its string id
p, err := greeters.GetInterface(pluginName)
if err != nil {
log.Fatal(err.Error())
}
log.Printf("\n\n%s: %s plugin gives me: %s\n\n", greeters.Type, pluginName, p.(plugin.Greeter).Greet())
}
}
func playWithClubbers() {
// Grab a new manager for dealing with "clubber" type plugins
clubbers := plugin.NewManager("clubber", "clubber-*", "./plugins/built", &plugin.ClubberPlugin{})
defer clubbers.Dispose()
// Initialize clubbers manager
err := clubbers.Init()
if err != nil {
log.Fatal(err.Error())
}
// Launch all clubbbers binaries
clubbers.Launch()
// Lets see what all the clubbers do when they party hardy!
for _, pluginName := range []string{"raver", "cowboy"} {
// grab a plugin by its string id
p, err := clubbers.GetInterface(pluginName)
if err != nil {
log.Fatal(err.Error())
}
log.Printf("\n%s: %s plugin gives me: %s\n", clubbers.Type, pluginName, p.(plugin.Clubber).FistPump())
}
}
func main() {
// excercise some greeter plugins
playWithGreeters()
// excercise some clubber plugins
playWithClubbers()
}