63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace MMOserver.Config;
|
|
|
|
public static class AppConfig
|
|
{
|
|
public static ServerConfig Server
|
|
{
|
|
get;
|
|
private set;
|
|
} = null!;
|
|
|
|
public static RestApiConfig RestApi
|
|
{
|
|
get;
|
|
private set;
|
|
} = null!;
|
|
|
|
public static void Initialize(IConfiguration config)
|
|
{
|
|
Server = new ServerConfig(config.GetSection("Server"));
|
|
RestApi = new RestApiConfig(config.GetSection("RestApi"));
|
|
}
|
|
}
|
|
|
|
public sealed class ServerConfig
|
|
{
|
|
public int Port
|
|
{
|
|
get;
|
|
}
|
|
|
|
public ServerConfig(IConfigurationSection section)
|
|
{
|
|
Port = int.Parse(section["Port"] ?? throw new InvalidOperationException("Server:Port is required in config.json"));
|
|
}
|
|
}
|
|
|
|
public sealed class RestApiConfig
|
|
{
|
|
public string BaseUrl
|
|
{
|
|
get;
|
|
}
|
|
|
|
public string VerifyToken
|
|
{
|
|
get;
|
|
}
|
|
|
|
public string ApiKey
|
|
{
|
|
get;
|
|
}
|
|
|
|
public RestApiConfig(IConfigurationSection section)
|
|
{
|
|
BaseUrl = section["BaseUrl"] ?? throw new InvalidOperationException("RestApi:BaseUrl is required in config.json");
|
|
VerifyToken = section["VerifyToken"] ?? throw new InvalidOperationException("RestApi:BaseUrl is required in config.json");
|
|
ApiKey = section["ApiKey"] ?? throw new InvalidOperationException("RestApi:ApiKey is required in config.json");
|
|
}
|
|
}
|