Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions go-1-8/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"os"
"plugin"

"github.com/golang-rennes/demo-plugins/go-1-8/types"
)

func main() {
Expand Down Expand Up @@ -32,18 +34,18 @@ func registerPlugin(path string) (*Plugin, error) {
return nil, err
}

funcSymbol, err := p.Lookup("Greetings")
interfaceSymbol, err := p.Lookup("Greeter")
if err != nil {
return nil, err
}

greet := funcSymbol.(func(...string) string)
greet := *interfaceSymbol.(*types.Greeter)

log.Printf("Plugin successfully installed\n")

plugin := &Plugin{
Path: path,
Greetings: greet,
Path: path,
Greeter: greet,
}

return plugin, nil
Expand Down
8 changes: 7 additions & 1 deletion go-1-8/reverse/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ package main
import (
"C"
"strings"

"github.com/golang-rennes/demo-plugins/go-1-8/types"
)

type reverseGreeter struct{}

func reverse(s string) (result string) {
for _, v := range s {
result = string(v) + result
}
return
}

func Greetings(args ...string) string {
func (g reverseGreeter) Greetings(args ...string) string {
name := reverse(strings.Join(args, "_"))
return name
}

var Greeter = types.Greeter(reverseGreeter{})
6 changes: 4 additions & 2 deletions go-1-8/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "github.com/golang-rennes/demo-plugins/go-1-8/types"

type Plugin struct {
Path string
Greetings func(...string) string
Path string
types.Greeter
}
3 changes: 3 additions & 0 deletions go-1-8/types/func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package types

type MyFunc func(...string) string
5 changes: 5 additions & 0 deletions go-1-8/types/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package types

type Greeter interface {
Greetings(args ...string) string
}
8 changes: 7 additions & 1 deletion go-1-8/world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ package main
import (
"C"
"strings"

"github.com/golang-rennes/demo-plugins/go-1-8/types"
)

func Greetings(args ...string) string {
type worldGreeter struct{}

func (g worldGreeter) Greetings(args ...string) string {
return "World " + strings.Join(args, " ")
}

var Greeter = types.Greeter(worldGreeter{})