mirror of
https://github.com/InazumaV/Ratte.git
synced 2026-02-04 04:30:09 +00:00
reactor: detach plugin config
This commit is contained in:
12
conf/conf.go
12
conf/conf.go
@@ -21,9 +21,9 @@ type Conf struct {
|
||||
// config fields
|
||||
Log Log `json:"Log,omitempty"`
|
||||
Watcher Watcher `json:"Watcher,omitempty"`
|
||||
Plugin Plugins `json:"Plugin,omitempty"` // Only accept from file path
|
||||
Core []Core `json:"Core,omitempty"`
|
||||
Acme []ACME `json:"Acme,omitempty"`
|
||||
Panel []Panel `json:"Panel,omitempty"`
|
||||
Node []Node `json:"Node,omitempty"`
|
||||
}
|
||||
|
||||
@@ -34,11 +34,11 @@ func New(path string) *Conf {
|
||||
WatchLocalConfig: true,
|
||||
WatchRemoteConfig: true,
|
||||
},
|
||||
Log: newLog(),
|
||||
Core: make([]Core, 0),
|
||||
Acme: make([]ACME, 0),
|
||||
Panel: make([]Panel, 0),
|
||||
Node: make([]Node, 0),
|
||||
Log: newLog(),
|
||||
Core: make([]Core, 0),
|
||||
Acme: make([]ACME, 0),
|
||||
Plugin: Plugins{},
|
||||
Node: make([]Node, 0),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
25
conf/core.go
25
conf/core.go
@@ -1,25 +0,0 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
type Core struct {
|
||||
Name string `json:"Name,omitempty"`
|
||||
Path string `json:"Path,omitempty"`
|
||||
DataPath string `json:"DataPath,omitempty"`
|
||||
Config json.RawMessage `json:"Config,omitempty"`
|
||||
}
|
||||
type _core Core
|
||||
|
||||
func (c *Core) UnmarshalJSON(data []byte) error {
|
||||
err := json.Unmarshal(data, (*_core)(c))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal core: %v", err)
|
||||
}
|
||||
if len(c.Config) == 0 {
|
||||
c.Config = data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package conf
|
||||
|
||||
type Panel struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
49
conf/plugin.go
Normal file
49
conf/plugin.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goccy/go-json"
|
||||
)
|
||||
|
||||
type Core struct {
|
||||
Type string `json:"type"`
|
||||
DataPath string `json:"DataPath,omitempty"`
|
||||
Config json.RawMessage `json:"Config,omitempty"`
|
||||
}
|
||||
type _core Core
|
||||
|
||||
func (c *Core) UnmarshalJSON(data []byte) error {
|
||||
err := json.Unmarshal(data, (*_core)(c))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal core: %v", err)
|
||||
}
|
||||
if len(c.Config) == 0 {
|
||||
c.Config = data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Plugins struct {
|
||||
Core []Plugin `json:"core"`
|
||||
Panel []Plugin `json:"panel"`
|
||||
}
|
||||
|
||||
type Plugin struct {
|
||||
Name string `json:"Name,omitempty"`
|
||||
Path string `json:"Path,omitempty"`
|
||||
}
|
||||
|
||||
type _plugins Plugins
|
||||
|
||||
func (p *Plugins) UnmarshalJSON(data []byte) error {
|
||||
var path string
|
||||
err := json.Unmarshal(data, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(data, (*_plugins)(p))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal plugin: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user