mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-21 13:38:56 +02:00
[GH-1256] feat: config file flag (#1418)
* feat: adds support for --config * feat: adds support for configFilePath in startServer * chore: removes ugly spacing
This commit is contained in:
parent
8b66243ca2
commit
5848ea1c07
@ -57,7 +57,7 @@ make
|
||||
|
||||
To start the server, run `./bin/focalboard-server`
|
||||
|
||||
Server settings are in config.json.
|
||||
Server settings are in config.json (or the path specified with --config).
|
||||
|
||||
Open a browser to [http://localhost:8000](http://localhost:8000) to start.
|
||||
|
||||
|
@ -87,8 +87,20 @@ func logInfo(logger *mlog.Logger) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// config.json file
|
||||
config, err := config.ReadConfigFile()
|
||||
// Command line args
|
||||
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
|
||||
pPort := flag.Int("port", 0, "the port number")
|
||||
pSingleUser := flag.Bool("single-user", false, "single user mode")
|
||||
pDBType := flag.String("dbtype", "", "Database type")
|
||||
pDBConfig := flag.String("dbconfig", "", "Database config")
|
||||
pConfigFilePath := flag.String(
|
||||
"config",
|
||||
"",
|
||||
"Location of the JSON config file",
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
config, err := config.ReadConfigFile(*pConfigFilePath)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to read the config file: ", err)
|
||||
return
|
||||
@ -114,14 +126,6 @@ func main() {
|
||||
|
||||
logInfo(logger)
|
||||
|
||||
// Command line args
|
||||
pMonitorPid := flag.Int("monitorpid", -1, "a process ID")
|
||||
pPort := flag.Int("port", config.Port, "the port number")
|
||||
pSingleUser := flag.Bool("single-user", false, "single user mode")
|
||||
pDBType := flag.String("dbtype", "", "Database type")
|
||||
pDBConfig := flag.String("dbconfig", "", "Database config")
|
||||
flag.Parse()
|
||||
|
||||
singleUser := false
|
||||
if pSingleUser != nil {
|
||||
singleUser = *pSingleUser
|
||||
@ -193,13 +197,14 @@ func main() {
|
||||
|
||||
// StartServer starts the server
|
||||
//export StartServer
|
||||
func StartServer(webPath *C.char, filesPath *C.char, port int, singleUserToken, dbConfigString *C.char) {
|
||||
func StartServer(webPath *C.char, filesPath *C.char, port int, singleUserToken, dbConfigString, configFilePath *C.char) {
|
||||
startServer(
|
||||
C.GoString(webPath),
|
||||
C.GoString(filesPath),
|
||||
port,
|
||||
C.GoString(singleUserToken),
|
||||
C.GoString(dbConfigString),
|
||||
C.GoString(configFilePath),
|
||||
)
|
||||
}
|
||||
|
||||
@ -209,14 +214,14 @@ func StopServer() {
|
||||
stopServer()
|
||||
}
|
||||
|
||||
func startServer(webPath string, filesPath string, port int, singleUserToken, dbConfigString string) {
|
||||
func startServer(webPath string, filesPath string, port int, singleUserToken, dbConfigString, configFilePath string) {
|
||||
if pServer != nil {
|
||||
stopServer()
|
||||
pServer = nil
|
||||
}
|
||||
|
||||
// config.json file
|
||||
config, err := config.ReadConfigFile()
|
||||
config, err := config.ReadConfigFile(configFilePath)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to read the config file: ", err)
|
||||
return
|
||||
|
@ -59,10 +59,13 @@ type Configuration struct {
|
||||
}
|
||||
|
||||
// ReadConfigFile read the configuration from the filesystem.
|
||||
func ReadConfigFile() (*Configuration, error) {
|
||||
viper.SetConfigName("config") // name of config file (without extension)
|
||||
viper.SetConfigType("json") // REQUIRED if the config file does not have the extension in the name
|
||||
viper.AddConfigPath(".") // optionally look for config in the working directory
|
||||
func ReadConfigFile(configFilePath string) (*Configuration, error) {
|
||||
if configFilePath == "" {
|
||||
viper.SetConfigFile("./config.json")
|
||||
} else {
|
||||
viper.SetConfigFile(configFilePath)
|
||||
}
|
||||
|
||||
viper.SetEnvPrefix("focalboard")
|
||||
viper.AutomaticEnv() // read config values from env like FOCALBOARD_SERVERROOT=...
|
||||
viper.SetDefault("ServerRoot", DefaultServerRoot)
|
||||
|
@ -116,7 +116,8 @@ namespace Focalboard {
|
||||
byte[] filesPathBytes = Encoding.UTF8.GetBytes(filesPath);
|
||||
byte[] sessionTokenBytes = Encoding.UTF8.GetBytes(sessionToken);
|
||||
byte[] dbPathBytes = Encoding.UTF8.GetBytes(dbPath);
|
||||
GoFunctions.StartServer(webFolderBytes, filesPathBytes, port, sessionTokenBytes, dbPathBytes);
|
||||
byte[] configFilePathBytes = Encoding.UTF8.GetBytes("");
|
||||
GoFunctions.StartServer(webFolderBytes, filesPathBytes, port, sessionTokenBytes, dbPathBytes, configFilePathBytes);
|
||||
|
||||
Debug.WriteLine("Server started");
|
||||
}
|
||||
@ -148,7 +149,7 @@ namespace Focalboard {
|
||||
|
||||
static class GoFunctions {
|
||||
[DllImport(@"focalboard-server.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void StartServer(byte[] webPath, byte[] filesPath, int port, byte[] singleUserToken, byte[] dbConfigString);
|
||||
public static extern void StartServer(byte[] webPath, byte[] filesPath, int port, byte[] singleUserToken, byte[] dbConfigString, byte[] configFilePath);
|
||||
|
||||
[DllImport(@"focalboard-server.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void StopServer();
|
||||
|
Loading…
Reference in New Issue
Block a user