Added entry-point initialization for a server instance

This commit is contained in:
Tristan B. Velloza Kildaire 2021-12-24 09:25:01 +02:00
parent f9c93d17c1
commit 8703cdc74d
4 changed files with 80 additions and 1 deletions

View File

@ -4,6 +4,10 @@
module dnetd.app;
import dlog;
import dnetd.exceptions : GeneralException;
import std.json : JSONValue;
import dnetd.config : readConfig, Configuration;
import dnetd.server : Server;
public Logger logger;
string VERSION = "v0.0.1";
@ -14,4 +18,19 @@ void main()
logger = new DefaultLogger();
logger.log("Welcome to dnetd v"~VERSION);
/* TODO: Add jcli handling here */
try
{
JSONValue jsonConfig = readConfig("config.json");
Configuration config = Configuration.fromJSON(jsonConfig);
/* TODO: Server init with config here */
Server server = new Server(config);
}
catch(GeneralException e)
{
}
}

View File

@ -5,12 +5,16 @@ module dnetd.config;
import dnetd.app : logger;
import std.json : JSONValue, JSONException;
import dnetd.exceptions;
/**
*
*/
public final class Configuration
{
/**
* Load the configuration from a JSON source, returning the
* configuration as a Configuration object, on error, null
* configuration as a Configuration object, on error, null (TODO: Throw exception rather)
*
* @param jsonConfig the JSONValue configuration
*/
@ -41,3 +45,28 @@ public final class Configuration
return config;
}
}
/**
* Reads in the JSON from the given path to the configuration
* file
*
* On error throws TODO
*/
public JSONValue readConfig(string path)
{
JSONValue config;
return config;
}
/**
* Configuration error
*/
public final class ConfigurationError : GeneralException
{
this()
{
}
}

16
source/dnetd/exceptions.d Normal file
View File

@ -0,0 +1,16 @@
/**
* Exceptions sub-system
*/
module dnetd.exceptions;
import std.exception;
/**
* Base class for all DNETD exceptions
*/
public class GeneralException : Exception
{
this()
{
}
}

View File

@ -6,3 +6,18 @@
* relates to it, such as users, server links and processing/handling
* of messages and commands.
*/
module dnetd.server;
import dnetd.app : logger;
import dnetd.config : Configuration;
/**
* Represents an instance of a dnet server
*/
public final class Server
{
this(Configuration config)
{
logger.log("Server instance '"~"PUT ID HERE"~"' starting up...");
}
}