updated logging
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fes/modules/config"
|
||||
"fes/modules/ui"
|
||||
"fmt"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
@@ -15,6 +14,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
/* this is the request data we pass over the bus to the application, via the fes.bus interface */
|
||||
@@ -378,18 +380,26 @@ func loadDirs() map[string]string {
|
||||
|
||||
/* helper to parse the Fes.toml and generate config */
|
||||
func parseConfig() config.AppConfig {
|
||||
defaultCfg := config.AppConfig{}
|
||||
defaultCfg.App.Authors = []string{"unknown"}
|
||||
defaultCfg.App.Name = "unknown"
|
||||
defaultCfg.App.Version = "unknown"
|
||||
|
||||
tomlDocument, err := os.ReadFile("Fes.toml")
|
||||
if err != nil {
|
||||
ui.Error("failed to read Fes.toml", err)
|
||||
os.Exit(1)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
ui.WARN("no config file found, using the default config. In order to specify a config file write to Fes.toml")
|
||||
return defaultCfg
|
||||
} else {
|
||||
ui.Error("failed to read Fes.toml", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
docStr := fixMalformedToml(string(tomlDocument))
|
||||
var cfg config.AppConfig
|
||||
if err := toml.Unmarshal([]byte(docStr), &cfg); err != nil {
|
||||
ui.Warning("failed to parse Fes.toml", err)
|
||||
cfg.App.Authors = []string{"unknown"}
|
||||
cfg.App.Name = "unknown"
|
||||
cfg.App.Version = "unknown"
|
||||
cfg = defaultCfg
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
@@ -466,6 +476,6 @@ func Start(dir string) error {
|
||||
w.Write(data)
|
||||
})
|
||||
|
||||
fmt.Printf("Server is running on http://localhost:%d\n", *config.Port)
|
||||
ui.Log("Ready to accept connections on http://localhost:%d", *config.Port)
|
||||
return http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *config.Port), nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user