additional changes
CI / Detect changed paths (pull_request) Successful in 21s
CI / Odin unit tests and build (pull_request) Successful in 45s
CI / API unit tests and lint (pull_request) Failing after 28s
CI / Infra unit tests, vet, and preview (pull_request) Successful in 43s

This commit is contained in:
2026-09-07 19:51:22 -06:00
parent 1443369f6c
commit fade4a17dc
8 changed files with 103 additions and 82 deletions
+5 -19
View File
@@ -12,10 +12,7 @@ import "core:strings"
// double quotes. Real process environment variables take precedence over the
// file. The returned map owns its keys/values; release it with destroy.
@(private)
parse :: proc(
src: string,
allocator := context.allocator,
) -> map[string]string {
parse :: proc(src: string, allocator := context.allocator) -> map[string]string {
result := make(map[string]string, allocator)
it := src
@@ -54,18 +51,12 @@ parse :: proc(
// parse_file reads a dotenv file from disk and parses it into a map. It
// returns (nil, false) when the file cannot be read (e.g. it does not exist).
parse_file :: proc(
filename: string,
allocator := context.allocator,
) -> (
map[string]string,
bool,
) {
parse_file :: proc(filename: string, allocator := context.allocator) -> (map[string]string, bool) {
data, err := os.read_entire_file(filename, allocator)
if err != nil {
return nil, false
}
defer delete(data)
defer delete(data, allocator)
return parse(string(data), allocator), true
}
@@ -86,8 +77,7 @@ destroy :: proc(env: map[string]string) {
// case-insensitive, so API_URL maps onto api_url (or an `env:"API_URL"` tag).
@(private)
env_key_for_field :: proc(field: reflect.Struct_Field) -> string {
if tag_key, ok := reflect.struct_tag_lookup(field.tag, "env");
ok && tag_key != "" {
if tag_key, ok := reflect.struct_tag_lookup(field.tag, "env"); ok && tag_key != "" {
return tag_key
}
return field.name
@@ -100,11 +90,7 @@ env_key_for_field :: proc(field: reflect.Struct_Field) -> string {
// and floats with strconv.parse_f64. Keys missing from env leave the field
// at its zero value. It returns false if a present value cannot be converted
// to the field's type.
decode :: proc(
env: map[string]string,
dest: ^$T,
allocator := context.allocator,
) -> bool {
decode :: proc(env: map[string]string, dest: ^$T, allocator := context.allocator) -> bool {
ti := reflect.type_info_base(type_info_of(T))
fields, ok := ti.variant.(runtime.Type_Info_Struct)
if !ok {