Runtime checks and clearing

This commit is contained in:
Max Chaev 2025-02-09 16:47:08 +03:00
parent afa67b3d3b
commit 63151ad724
5 changed files with 37 additions and 10 deletions

View File

@ -1,6 +0,0 @@
@RestySqlite_HostAddress = http://localhost:5063
GET {{RestySqlite_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -4,8 +4,35 @@ namespace RestySqlite
{
public class Utils
{
public static dynamic ReadConfig(string key, string? category = null)
public static dynamic? ReadConfig(string key, string? category = null)
{
if (!File.Exists("conf.toml"))
{
TomlTable toml = new TomlTable
{
["title"] = "Configuration file for API",
["api"] =
{
["port"] = 5417,
["handle"] = "api",
},
["sql"] =
{
["database"] = ""
}
};
using(StreamWriter writer = File.CreateText("conf.toml"))
{
toml.WriteTo(writer);
// Remember to flush the data if needed!
writer.Flush();
}
Console.WriteLine("Config created please check it.");
return null;
}
using(StreamReader reader = File.OpenText("conf.toml"))
{
TomlTable table = TOML.Parse(reader);

View File

@ -17,6 +17,12 @@ namespace RestySqlite
return;
}
if (!File.Exists($"{dbName}.db"))
{
Console.WriteLine($"Database {dbName}.db not found in folder!");
return;
}
string handle = Utils.ReadConfig("handle", "api");
int port = Utils.ReadConfig("port", "api");

View File

@ -1,8 +1,8 @@
title = "Configuration file for API"
[api]
port=5417
handle="api"
port = 5417
handle = "api"
[sql]
database="test"
database = "test"

BIN
test.db

Binary file not shown.