mirror of
https://gitlab.com/nullmax17/RestySqlite.git
synced 2025-03-14 16:01:13 +03:00
48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Tommy;
|
|
|
|
namespace RestySqlite
|
|
{
|
|
public class Utils
|
|
{
|
|
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);
|
|
|
|
if (category != null)
|
|
{
|
|
return table[category][key];
|
|
}
|
|
return table[key];
|
|
}
|
|
}
|
|
}
|
|
} |