if used as library, allow that the auth and bridge plugins can be set by (#79)
struct, and not only by name
This commit is contained in:
1 parent
55f1f1aa80
commit
17dac26996
4 files changed
+21
-11
No files matched your search
+2
-2
@@ -92,8 +92,8 @@ func NewBroker(config *Config) (*Broker, error) {
|
||||
b.tlsConfig = tlsconfig
|
||||
}
|
||||
|
||||
b.auth = auth.NewAuth(b.config.Plugin.Auth)
|
||||
b.bridgeMQ = bridge.NewBridgeMQ(b.config.Plugin.Bridge)
|
||||
b.auth = b.config.Plugin.Auth
|
||||
b.bridgeMQ = b.config.Plugin.Bridge
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/fhmq/hmq/logger"
|
||||
"github.com/fhmq/hmq/plugins/auth"
|
||||
"github.com/fhmq/hmq/plugins/bridge"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -32,6 +34,11 @@ type Config struct {
|
||||
}
|
||||
|
||||
type Plugins struct {
|
||||
Auth auth.Auth
|
||||
Bridge bridge.BridgeMQ
|
||||
}
|
||||
|
||||
type NamedPlugins struct {
|
||||
Auth string
|
||||
Bridge string
|
||||
}
|
||||
@@ -152,6 +159,18 @@ func LoadConfig(filename string) (*Config, error) {
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
|
||||
func (p *Plugins) UnmarshalJSON(b []byte) error {
|
||||
var named NamedPlugins
|
||||
err := json.Unmarshal(b, &named)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Auth = auth.NewAuth(named.Auth)
|
||||
p.Bridge = bridge.NewBridgeMQ(named.Bridge)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (config *Config) check() error {
|
||||
|
||||
if config.Worker == 0 {
|
||||
|
||||
Reference in new issue
Block a user