A dotenv library for zig.
- Zig >= 0.15.0-dev.337+4e700fdf8
Add the dependency to your project:
zig fetch --save=zig-dotenv git+https://github.com/deatil/zig-dotenv#main
or use local path to add dependency at build.zig.zon
file
.{
.dependencies = .{
.@"zig-dotenv" = .{
.path = "./lib/zig-dotenv",
},
...
}
}
And the following to your build.zig
file:
const zig_totp_dep = b.dependency("zig-dotenv", .{});
exe.root_module.addImport("zig-dotenv", zig_totp_dep.module("zig-dotenv"));
The zig-dotenv
structure can be imported in your application with:
const dotenv = @import("zig-dotenv");
const std = @import("std");
const dotenv = @import("zig-dotenv");
pub fn main() !void {
const alloc = std.heap.page_allocator;
const env_data =
\\FOO=abc
\\BAR="def ghi"
\\# Test
\\BAZ=xyz
;
var env = dotenv.Dotenv.init(alloc, .{});
defer env.deinit();
try env.parse(env_data);
const got_foo = env.get("FOO").?;
// output:
// dotenv got: abc
std.debug.print("dotenv got: {s} \n", .{got_foo});
}
- The library LICENSE is
Apache2
, using the library need keep the LICENSE.
- Copyright deatil(https://github.com/deatil).