Skip to main content

src/aws@env.erl

-module(aws@env).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/aws/env.gleam").
-export([get_env/1]).

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

?MODULEDOC(
    " OS environment-variable access.\n"
    "\n"
    " A typed wrapper over Erlang's `os:getenv/1`: `Ok(value)` when the\n"
    " variable is set, `Error(Nil)` when it is not. The credential chain and\n"
    " region resolver read the environment internally; this exposes the same\n"
    " accessor for application code — for example a Lambda handler reading its\n"
    " configured `MY_BUCKET` / `MY_TABLE` without hand-rolling an FFI.\n"
).

-file("src/aws/env.gleam", 13).
?DOC(
    " Read an OS environment variable, returning `Error(Nil)` if it is unset.\n"
    " (`os:getenv/1` deals in charlists; this bridges to/from Gleam `String`\n"
    " and maps the unset miss to `Error(Nil)`.)\n"
).
-spec get_env(binary()) -> {ok, binary()} | {error, nil}.
get_env(Name) ->
    aws_ffi:get_env(Name).