58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
// Package config
|
|
// Path: /internal/platform/config
|
|
// File: load.go
|
|
//
|
|
// Purpose
|
|
// Responsible solely for loading strongly-typed application configuration
|
|
// from a JSON file on disk. This is the *input* stage of configuration
|
|
// lifecycle — the resulting Config is consumed by bootstrap and may be
|
|
// optionally stored globally via config.Init().
|
|
//
|
|
// Responsibilities (as implemented here)
|
|
// 1) Read configuration JSON file from a specified path.
|
|
// 2) Deserialize into the Config struct (strongly typed).
|
|
// 3) Return the populated Config value or an error.
|
|
//
|
|
// Design notes
|
|
// - Path is caller-controlled (bootstrap decides where config.json lives).
|
|
// - No defaults or validation are enforced here — errors bubble to bootstrap.
|
|
// - Pure function: no globals mutated, safe for tests and reuse.
|
|
// - Load returns a **value**, not a pointer, avoiding accidental mutation
|
|
// unless caller explicitly stores it.
|
|
//
|
|
// TODOs (from current architecture direction)
|
|
// - Add schema validation for required config fields.
|
|
// - Add environment override support for deployment flexibility.
|
|
// - Consider merging with a future layered config system (file + env + flags).
|
|
// - Emit structured errors including path details for troubleshooting.
|
|
//
|
|
// Change log
|
|
// [2025-10-29] Documentation aligned with bootstrap integration and config.Init() use.
|
|
|
|
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
// Load reads the JSON configuration file located at `path`
|
|
// and unmarshals it into a Config struct.
|
|
//
|
|
// Caller is responsible for passing the result into bootstrap and/or
|
|
// config.Init() to make it globally available.
|
|
func Load(path string) (Config, error) {
|
|
var cfg Config
|
|
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return cfg, err
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
return cfg, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|