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:
Jakub Zych
2026-09-16 13:24:30 +02:00
parent 5f2291849d
commit 86969739ae
17 changed files with 297 additions and 12 deletions

View 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{})
}