added support for dotenv files and config
CI / Detect changed paths (pull_request) Failing after 34m20s
CI / Infra unit tests, vet, and preview (pull_request) Has been skipped
CI / API unit tests and lint (pull_request) Failing after 34m36s
CI / Odin unit tests and build (pull_request) Failing after 34m49s

This commit is contained in:
2026-09-07 13:27:51 -06:00
parent 3803787fe8
commit ac2d30510c
7 changed files with 242 additions and 8 deletions
+29
View File
@@ -0,0 +1,29 @@
package main
import "lib:dotenv"
Config :: struct {
api_url: string,
}
get_config :: proc() -> (^Config, ^Error) {
env, _ := dotenv.parse_file(".env", context.temp_allocator)
defer dotenv.destroy(env)
c := new(Config)
c.api_url = dotenv.get_string(env, "API_URL")
if err := validate_config(c); err != nil {
return nil, err
}
return c, nil
}
validate_config :: proc(c: ^Config) -> ^Error {
err := new(Error)
if c.api_url == "" do err.type = .Config; err.message = "'API_URL' is required"
return err
}
+20
View File
@@ -0,0 +1,20 @@
package main
import "core:fmt"
import "core:strings"
ErrorType :: enum {
Config,
API,
}
Error :: struct {
type: ErrorType,
message: string,
}
format_error :: proc(err: ^Error) -> string {
sb := strings.builder_make(context.temp_allocator)
return fmt.sbprintf(&sb, "[%s] => %s", err.type, err.message)
}
+8 -7
View File
@@ -24,6 +24,13 @@ universe: [dynamic]Galaxy
rng: rand.Default_Random_State
main :: proc() {
c: ^Config
if c, err := get_config(); err != nil {
panic(format_error(err))
}
rng = rand.create(0xDE51_0000)
context.random_generator = rand.default_random_generator(&rng)
@@ -103,11 +110,5 @@ draw :: proc() {
}
rl.DrawFPS(10, 10)
rl.DrawText(
"DESI Explorer — drag to rotate, scroll to zoom",
10,
34,
18,
rl.RAYWHITE,
)
rl.DrawText("DESI Explorer — drag to rotate, scroll to zoom", 10, 34, 18, rl.RAYWHITE)
}