WIP: extension feature
This commit is contained in:
1
example/extendable/.gitignore
vendored
Normal file
1
example/extendable/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin
|
11
example/extendable/Makefile
Normal file
11
example/extendable/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
build: extension
|
||||
go build -o ./bin/app ./
|
||||
|
||||
extension:
|
||||
go build -o ./bin/myext.so -buildmode=plugin ./myext
|
||||
|
||||
watch:
|
||||
modd
|
||||
|
||||
run:
|
||||
./bin/app
|
23
example/extendable/main.go
Normal file
23
example/extendable/main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/extension"
|
||||
)
|
||||
|
||||
func main() {
|
||||
reg := extension.NewRegistry()
|
||||
ctx := context.Background()
|
||||
|
||||
extensions, err := reg.LoadAll(ctx, "./bin/*.so")
|
||||
if err != nil {
|
||||
log.Fatal(errors.WithStack(err))
|
||||
}
|
||||
|
||||
for _, ext := range extensions {
|
||||
log.Printf("Loaded extension '%s', version '%s'", ext.ExtensionName(), ext.ExtensionVersion())
|
||||
}
|
||||
}
|
6
example/extendable/modd.conf
Normal file
6
example/extendable/modd.conf
Normal file
@ -0,0 +1,6 @@
|
||||
**/*.go
|
||||
modd.conf
|
||||
Makefile {
|
||||
prep: make build
|
||||
prep: make run
|
||||
}
|
12
example/extendable/myext/extension.go
Normal file
12
example/extendable/myext/extension.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
type MyExtension struct {
|
||||
}
|
||||
|
||||
func (e *MyExtension) ExtensionName() string {
|
||||
return "my.extension"
|
||||
}
|
||||
|
||||
func (e *MyExtension) ExtensionVersion() string {
|
||||
return "0.0.0"
|
||||
}
|
11
example/extendable/myext/main.go
Normal file
11
example/extendable/myext/main.go
Normal file
@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlab.com/wpetit/goweb/extension"
|
||||
)
|
||||
|
||||
func RegisterExtension(ctx context.Context) (extension.Extension, error) {
|
||||
return &MyExtension{}, nil
|
||||
}
|
Reference in New Issue
Block a user