update Config structure and add node name parameter

This commit is contained in:
2025-07-31 21:30:59 +03:00
parent a5a7354061
commit 45e541ac00
6 changed files with 19 additions and 11 deletions

View File

@@ -185,6 +185,7 @@ func Init6Hook(cs *corestate.CoreState, x *app.AppX) {
} }
x.Config.Conf.Log.Level = &logs.Levels.Fallback x.Config.Conf.Log.Level = &logs.Levels.Fallback
} }
x.Log.Printf("Starting \"%s\" node", *x.Config.Conf.Node.Name)
} }
func Init7Hook(cs *corestate.CoreState, x *app.AppX) { func Init7Hook(cs *corestate.CoreState, x *app.AppX) {

View File

@@ -43,8 +43,9 @@ func (c *Compositor) LoadConf(path string) error {
v.SetConfigType("yaml") v.SetConfigType("yaml")
// defaults // defaults
v.SetDefault("mode", "dev") v.SetDefault("node.name", "noname")
v.SetDefault("com_dir", "./com/") v.SetDefault("node.mode", "dev")
v.SetDefault("node.com_dir", "./com/")
v.SetDefault("http_server.address", "0.0.0.0") v.SetDefault("http_server.address", "0.0.0.0")
v.SetDefault("http_server.port", "8080") v.SetDefault("http_server.port", "8080")
v.SetDefault("http_server.timeout", "5s") v.SetDefault("http_server.timeout", "5s")

View File

@@ -18,8 +18,7 @@ type Compositor struct {
} }
type Conf struct { type Conf struct {
Mode *string `mapstructure:"mode"` Node *Node `mapstructure:"node"`
ComDir *string `mapstructure:"com_dir"`
HTTPServer *HTTPServer `mapstructure:"http_server"` HTTPServer *HTTPServer `mapstructure:"http_server"`
TLS *TLS `mapstructure:"tls"` TLS *TLS `mapstructure:"tls"`
Updates *Updates `mapstructure:"updates"` Updates *Updates `mapstructure:"updates"`
@@ -27,6 +26,12 @@ type Conf struct {
DisableWarnings *[]string `mapstructure:"disable_warnings"` DisableWarnings *[]string `mapstructure:"disable_warnings"`
} }
type Node struct {
Mode *string `mapstructure:"mode"`
Name *string `mapstructure:"name"`
ComDir *string `mapstructure:"com_dir"`
}
type HTTPServer struct { type HTTPServer struct {
Address *string `mapstructure:"address"` Address *string `mapstructure:"address"`
Port *string `mapstructure:"port"` Port *string `mapstructure:"port"`

View File

@@ -16,6 +16,7 @@ import (
) )
var GlobalLevel slog.Level var GlobalLevel slog.Level
type levelsStruct struct { type levelsStruct struct {
Available []string Available []string
Fallback string Fallback string

View File

@@ -213,7 +213,7 @@ func (h *HandlerV1) handleLUA(r *http.Request, req *rpc.RPCRequest, path string)
L.SetField(net, "Http", netHttp) L.SetField(net, "Http", netHttp)
L.SetGlobal("Net", net) L.SetGlobal("Net", net)
prep := filepath.Join(*h.x.Config.Conf.ComDir, "_prepare.lua") prep := filepath.Join(*h.x.Config.Conf.Node.ComDir, "_prepare.lua")
if _, err := os.Stat(prep); err == nil { if _, err := os.Stat(prep); err == nil {
if err := L.DoFile(prep); err != nil { if err := L.DoFile(prep); err != nil {
return rpc.NewError(rpc.ErrInternalError, err.Error(), req.ID) return rpc.NewError(rpc.ErrInternalError, err.Error(), req.ID)

View File

@@ -16,7 +16,7 @@ func (h *HandlerV1) resolveMethodPath(method string) (string, error) {
parts := strings.Split(method, ">") parts := strings.Split(method, ">")
relPath := filepath.Join(parts...) + ".lua" relPath := filepath.Join(parts...) + ".lua"
fullPath := filepath.Join(*h.x.Config.Conf.ComDir, relPath) fullPath := filepath.Join(*h.x.Config.Conf.Node.ComDir, relPath)
if _, err := os.Stat(fullPath); os.IsNotExist(err) { if _, err := os.Stat(fullPath); os.IsNotExist(err) {
return "", errors.New(rpc.ErrMethodNotFoundS) return "", errors.New(rpc.ErrMethodNotFoundS)