Refactoring rest server

This commit is contained in:
Mihail Slobodyanuk 2022-12-22 09:32:56 +02:00
parent 5469f3506b
commit 8b2b158284
3 changed files with 319 additions and 231 deletions

View file

@ -28,15 +28,17 @@ import (
"github.com/RiV-chain/RiV-mesh/src/core"
//"github.com/RiV-chain/RiV-mesh/src/ipv6rwc"
"github.com/RiV-chain/RiV-mesh/src/multicast"
"github.com/RiV-chain/RiV-mesh/src/restapi"
"github.com/RiV-chain/RiV-mesh/src/tun"
"github.com/RiV-chain/RiV-mesh/src/version"
)
type node struct {
core *core.Core
tun *tun.TunAdapter
multicast *multicast.Multicast
admin *admin.AdminSocket
core *core.Core
tun *tun.TunAdapter
multicast *multicast.Multicast
admin *admin.AdminSocket
rest_server *restapi.RestServer
}
func setLogLevel(loglevel string, logger *log.Logger) {
@ -262,6 +264,21 @@ func run(args yggArgs, ctx context.Context) {
}
}
// Setup the REST socket.
{
if n.rest_server, err = restapi.NewRestServer(restapi.RestServerCfg{
Core: n.core,
Log: logger,
ListenAddress: cfg.HttpAddress,
WwwRoot: cfg.WwwRoot,
ConfigFn: args.useconffile,
}); err != nil {
logger.Errorln(err)
} else {
err = n.rest_server.Serve()
}
}
// Setup the admin socket.
{
options := []admin.SetupOption{
@ -275,9 +292,6 @@ func run(args yggArgs, ctx context.Context) {
}
}
// Start HTTP server
n.admin.StartHttpServer(args.useconffile, cfg)
// Setup the multicast module.
{
options := []multicast.SetupOption{}