mirror of
https://github.com/InazumaV/Ratte.git
synced 2026-02-04 04:30:09 +00:00
feat: use wire
This commit is contained in:
50
boot/boot.go
Normal file
50
boot/boot.go
Normal file
@@ -0,0 +1,50 @@
|
||||
//go:build wireinject
|
||||
|
||||
package boot
|
||||
|
||||
import (
|
||||
"github.com/InazumaV/Ratte/conf"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
var preSet = wire.NewSet(
|
||||
wire.FieldsOf(new(*conf.Conf), "ACME", "Plugin"),
|
||||
wire.FieldsOf(new(conf.Plugins), "Core", "Panel"),
|
||||
initAcme,
|
||||
initCores,
|
||||
initPanels,
|
||||
)
|
||||
var mainSet = wire.NewSet(
|
||||
wire.FieldsOf(new(*conf.Conf), "Node"),
|
||||
initNode,
|
||||
)
|
||||
|
||||
type Boot struct {
|
||||
Acmes AcmeGroup
|
||||
Cores CoreGroup
|
||||
Panels PanelGroup
|
||||
Node *NodeGroup
|
||||
}
|
||||
|
||||
func (b *Boot) Start() error {
|
||||
if err := b.Node.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Boot) Close() error {
|
||||
b.Node.Close()
|
||||
b.Cores.Close()
|
||||
b.Panels.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitBoot(c *conf.Conf) (*Boot, error) {
|
||||
wire.Build(
|
||||
preSet,
|
||||
mainSet,
|
||||
wire.Struct(new(Boot), "*"),
|
||||
)
|
||||
return nil, nil
|
||||
}
|
||||
Reference in New Issue
Block a user