feat(01-02): add optional plugin services and HasPlugin
- App-scoped typed Publish/Lookup with duplicate-provider errors - Set plugin IDs before Register so HasPlugin sees the full set - Greeter uses pact.OptionalMessage without importing optional
This commit is contained in:
43
examples/hello/plugins/optional/plugin.go
Normal file
43
examples/hello/plugins/optional/plugin.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package optional
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
|
||||
"git.golem15.com/golem15/summercms/backpack"
|
||||
"git.golem15.com/golem15/summercms/pact"
|
||||
"git.golem15.com/golem15/summercms/party"
|
||||
)
|
||||
|
||||
//go:embed config
|
||||
var configFS embed.FS
|
||||
|
||||
// Plugin is the golem15.optional plugin. Greeter may use it without importing this package.
|
||||
type Plugin struct{}
|
||||
|
||||
func (p *Plugin) ID() string { return "golem15.optional" }
|
||||
func (p *Plugin) Requires() []string { return nil }
|
||||
|
||||
func (p *Plugin) Register(app *backpack.App) error {
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
return app.Publish[pact.OptionalMessage](extra{})
|
||||
}
|
||||
|
||||
func (p *Plugin) Boot(*backpack.App) error { return nil }
|
||||
|
||||
func (p *Plugin) ConfigFS() fs.FS { return configFS }
|
||||
|
||||
type extra struct{}
|
||||
|
||||
func (extra) Message() string { return "hello-from-optional" }
|
||||
|
||||
var (
|
||||
_ pact.HasConfig = (*Plugin)(nil)
|
||||
_ pact.OptionalMessage = extra{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
party.Register(&Plugin{})
|
||||
}
|
||||
Reference in New Issue
Block a user