1
0
forked from MTSR/mapserver

feat(config): make WorldPath & DataPth configurable (#332)

This commit is contained in:
Nold 2023-09-18 06:47:29 +02:00 committed by GitHub
parent 53689acf53
commit 2114ee5c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -127,6 +127,8 @@ func ParseConfig(filename string) (*Config, error) {
MapBlockAccessorCfg: &mapblockaccessor, MapBlockAccessorCfg: &mapblockaccessor,
DefaultOverlays: defaultoverlays, DefaultOverlays: defaultoverlays,
Skins: &skins, Skins: &skins,
WorldPath: "./",
DataPath: "./",
} }
info, err := os.Stat(filename) info, err := os.Stat(filename)

View File

@ -20,6 +20,7 @@ import (
"github.com/minetest-go/colormapping" "github.com/minetest-go/colormapping"
"os" "os"
"path/filepath"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -33,14 +34,14 @@ func Setup(p params.ParamsType, cfg *Config) *App {
a.WebEventbus = eventbus.New() a.WebEventbus = eventbus.New()
//Parse world config //Parse world config
a.Worldconfig = worldconfig.Parse("world.mt") a.Worldconfig = worldconfig.Parse(filepath.Join(a.Config.WorldPath, "world.mt"))
logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver") logrus.WithFields(logrus.Fields{"version": Version}).Info("Starting mapserver")
var err error var err error
switch a.Worldconfig[worldconfig.CONFIG_BACKEND] { switch a.Worldconfig[worldconfig.CONFIG_BACKEND] {
case worldconfig.BACKEND_SQLITE3: case worldconfig.BACKEND_SQLITE3:
map_path := "map.sqlite" map_path := filepath.Join(a.Config.WorldPath, "map.sqlite")
// check if the database exists, otherwise abort (nothing to render/display) // check if the database exists, otherwise abort (nothing to render/display)
_, err := os.Stat(map_path) _, err := os.Stat(map_path)
@ -99,11 +100,11 @@ func Setup(p params.ParamsType, cfg *Config) *App {
} }
//load provided colors, if available //load provided colors, if available
info, err := os.Stat("colors.txt") info, err := os.Stat(filepath.Join(a.Config.DataPath, "colors.txt"))
if info != nil && err == nil { if info != nil && err == nil {
logrus.WithFields(logrus.Fields{"filename": "colors.txt"}).Info("Loading colors from filesystem") logrus.WithFields(logrus.Fields{"filename": "colors.txt"}).Info("Loading colors from filesystem")
data, err := os.ReadFile("colors.txt") data, err := os.ReadFile(filepath.Join(a.Config.DataPath, "colors.txt"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -124,7 +125,7 @@ func Setup(p params.ParamsType, cfg *Config) *App {
if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" { if a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER] != "" {
a.Objectdb, err = postgresobjdb.New(a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER]) a.Objectdb, err = postgresobjdb.New(a.Worldconfig[worldconfig.CONFIG_PSQL_MAPSERVER])
} else { } else {
a.Objectdb, err = sqliteobjdb.New("mapserver.sqlite") a.Objectdb, err = sqliteobjdb.New(filepath.Join(a.Config.DataPath, "mapserver.sqlite"))
} }
if err != nil { if err != nil {
@ -139,7 +140,7 @@ func Setup(p params.ParamsType, cfg *Config) *App {
} }
//create tiledb //create tiledb
a.TileDB, err = tiledb.New("./mapserver.tiles") a.TileDB, err = tiledb.New(filepath.Join(a.Config.DataPath, "mapserver.tiles"))
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -24,6 +24,8 @@ type Config struct {
MapBlockAccessorCfg *MapBlockAccessorConfig `json:"mapblockaccessor"` MapBlockAccessorCfg *MapBlockAccessorConfig `json:"mapblockaccessor"`
DefaultOverlays []string `json:"defaultoverlays"` DefaultOverlays []string `json:"defaultoverlays"`
Skins *SkinsConfig `json:"skins"` Skins *SkinsConfig `json:"skins"`
WorldPath string `json:"worldpath"`
DataPath string `json:"datapath"`
} }
type MapBlockAccessorConfig struct { type MapBlockAccessorConfig struct {