GitRCFS 1.3.1
dotnet add package GitRCFS --version 1.3.1
NuGet\Install-Package GitRCFS -Version 1.3.1
<PackageReference Include="GitRCFS" Version="1.3.1" />
paket add GitRCFS --version 1.3.1
#r "nuget: GitRCFS, 1.3.1"
// Install GitRCFS as a Cake Addin #addin nuget:?package=GitRCFS&version=1.3.1 // Install GitRCFS as a Cake Tool #tool nuget:?package=GitRCFS&version=1.3.1
GitRCFS - Git Remote Config Filesystem
What is GitRCFS?
GitRCFS
offers a lightweight option to synchronize an application's configuration & data files with a remote git repository. This library provides a simple api to use a git repository to access readonly configuration files.
Why is this useful?
There are 2 main benefits to using remote git repositories for configuration file hosting.
GitRCFS
enables configuration files to be synced across numerous different servers / devices. This saves the hassle of updating configuration files manually, and offers a single place to manage config files.- Another benefit is due to using Git as a version control, as a result,
GitRCFS
inherits all the benefits of Git. This way, config files could be shared across teams, rolled back, and be used in a much more flexible way.
Using GitRCFS
The GitRCFS library is extremely simple to use.
First create a FileRepository
,
var repo = new FileRepository("https://github.com/encodeous/gitrcfstest",
branch: "main", accessToken: "<your-token>", updateFrequencyMs: 5000);
You can optionally specify an access token, the branch to access the configuration files, and how frequently to check for configuration updates.
To access a file in the filesystem, there are 2 main ways:
- Use the
/
operator to combine a pathvar configFile = repo / "config-dir" / "config.json";
- Use the
[]
operator to select a pathvar configFile = repo["config-dir/config.json"];
All files and directories are of the type RcfsNode
Through this type, it is possible to listen for file changes, iterate the children of directories, and get the data from files.
Samples
Here are some code snippets showing the usage of GitRCFS
.
Read data from repo
// simple use case to read data from a repo:
var repo = new FileRepository("https://github.com/encodeous/gitrcfstest");
Console.WriteLine($"File content from repo: \"{repo["folder/file-in-folder.txt"].GetStringData()}\"");
Reading serialized data from repo
// deserializing a file into a C# class
var repo = new FileRepository("https://github.com/encodeous/gitrcfstest");
Console.WriteLine($"Time is {repo["serialized.json"].DeserializeData<DateTime>()}");
Monitoring repo for changes
// monitor for changes
var repo = new FileRepository("https://github.com/encodeous/gitrcfstest");
var file = repo["folder/file-in-folder.txt"];
Console.WriteLine($"Initial file content from repo: \"{file.GetStringData()}\"");
// file changed event handler
file.ContentsChanged += (_,_) =>
{
Console.WriteLine($"New file content: \"{file.GetStringData()}\"");
};
Authenticating
// simple use case to read data from a repo when logged in:
var repo = new FileRepository("https://github.com/encodeous/gitrcfstest", username: "user", password: "password");
Console.WriteLine($"File content from repo: \"{repo["folder/file-in-folder.txt"].GetStringData()}\"");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- LibGit2Sharp (>= 0.29.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.