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:
@@ -5,12 +5,14 @@ import (
|
||||
|
||||
"git.golem15.com/golem15/summercms/backpack"
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
"git.golem15.com/golem15/summercms/pact"
|
||||
"git.golem15.com/golem15/summercms/party"
|
||||
)
|
||||
|
||||
// Plugin is the golem15.greeter plugin. It requires golem15.hello.
|
||||
type Plugin struct {
|
||||
app *backpack.App
|
||||
app *backpack.App
|
||||
extra string
|
||||
}
|
||||
|
||||
func (p *Plugin) ID() string { return "golem15.greeter" }
|
||||
@@ -20,6 +22,12 @@ func (p *Plugin) Register(*backpack.App) error { return nil }
|
||||
|
||||
func (p *Plugin) Boot(app *backpack.App) error {
|
||||
p.app = app
|
||||
p.extra = ""
|
||||
if app != nil && app.HasPlugin("golem15.optional") {
|
||||
if msg, ok := app.Lookup[pact.OptionalMessage](); ok {
|
||||
p.extra = msg.Message()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,12 +44,14 @@ func (p *Plugin) Commands() []bonfire.Command {
|
||||
posts = p.app.Config.Int("golem15.hello.posts_per_page")
|
||||
debug = p.app.Config.Bool("app.debug")
|
||||
}
|
||||
out.Printf("name=%s posts_per_page=%d debug=%t\n", name, posts, debug)
|
||||
out.Printf("name=%s posts_per_page=%d debug=%t extra=%s\n", name, posts, debug, p.extra)
|
||||
return nil
|
||||
},
|
||||
}}
|
||||
}
|
||||
|
||||
var _ pact.HasCommands = (*Plugin)(nil)
|
||||
|
||||
func init() {
|
||||
party.Register(&Plugin{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user