mirror of
https://gitlab.com/nullmax17/RestySqlite.git
synced 2025-03-14 16:01:13 +03:00
Runtime checks and clearing
This commit is contained in:
parent
afa67b3d3b
commit
63151ad724
@ -1,6 +0,0 @@
|
||||
@RestySqlite_HostAddress = http://localhost:5063
|
||||
|
||||
GET {{RestySqlite_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
29
Utils.cs
29
Utils.cs
@ -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);
|
||||
|
@ -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");
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
title = "Configuration file for API"
|
||||
|
||||
[api]
|
||||
port=5417
|
||||
handle="api"
|
||||
port = 5417
|
||||
handle = "api"
|
||||
|
||||
[sql]
|
||||
database="test"
|
||||
database = "test"
|
||||
|
Loading…
x
Reference in New Issue
Block a user