You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a MicroLibrary, the code is trivial enough
Consider just copypasting the file dotenv.zig into your project instead of adding yet another microdependency
Its only about 20 lines of code
Up to you
Usage
constdotenv=@import("dotenv");
pubfnmain() !void {
// create an allocatorvargpa=std.heap.GeneralPurposeAllocator(.{}){};
constallocator=gpa.allocator();
defergpa.deinit();
// init the dotenv object - this will read the .env file at runtimevarenv=trydotenv.init(allocator, ".env");
deferenv.deinit();
// gen "Env" varsvardatabase_host=env.get("DATABASE_HOST") orelse"localhost";
vardatabase_name=env.get("DATABASE_NAME") orelse"zigzag-data";
...dostuff// change the value of the DATABASE_HOSTtryenv.put("DATABASE_HOST", "postgres.local");
}
How it works
On boot, loads the .env file, and parses each line
If the line contains an '=' char, then it splits the line on that first '=' and then
adds KEY : VALUE to the environment.
Uses std.process.EnvMap - which is an in-memory clone of the initial ENV