mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 11:51:37 +00:00
Add GenerateConfigJSON, fix StartJSON
This commit is contained in:
parent
f7b0a85b5e
commit
d10a0d6137
@ -3,6 +3,7 @@
|
|||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -23,7 +24,7 @@ func (c *Core) StartAutoconfigure() error {
|
|||||||
logger := log.New(os.Stdout, "", 0)
|
logger := log.New(os.Stdout, "", 0)
|
||||||
nc := config.GenerateConfig(true)
|
nc := config.GenerateConfig(true)
|
||||||
nc.IfName = "dummy"
|
nc.IfName = "dummy"
|
||||||
nc.AdminListen = "tcp://[::]:9001"
|
nc.AdminListen = "tcp://localhost:9001"
|
||||||
nc.Peers = []string{}
|
nc.Peers = []string{}
|
||||||
if hostname, err := os.Hostname(); err == nil {
|
if hostname, err := os.Hostname(); err == nil {
|
||||||
nc.NodeInfo = map[string]interface{}{"name": hostname}
|
nc.NodeInfo = map[string]interface{}{"name": hostname}
|
||||||
@ -49,12 +50,29 @@ func (c *Core) StartJSON(configjson []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nc.IfName = "dummy"
|
nc.IfName = "dummy"
|
||||||
|
for _, ll := range nc.MulticastInterfaces {
|
||||||
|
ifceExpr, err := regexp.Compile(ll)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
c.AddMulticastInterfaceExpr(ifceExpr)
|
||||||
|
}
|
||||||
if err := c.Start(nc, logger); err != nil {
|
if err := c.Start(nc, logger); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateConfigJSON() []byte {
|
||||||
|
nc := config.GenerateConfig(false)
|
||||||
|
nc.IfName = "dummy"
|
||||||
|
if json, err := json.Marshal(nc); err == nil {
|
||||||
|
return json
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Core) GetAddressString() string {
|
func (c *Core) GetAddressString() string {
|
||||||
return c.GetAddress().String()
|
return c.GetAddress().String()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user