mirgation docs and inital migration
This commit is contained in:
commit
e706f7d907
3 files changed
+94
No files matched your search
@@ -0,0 +1,78 @@
|
|||||||
|
// Package config loads platform configuration from the environment.
|
||||||
|
//
|
||||||
|
// The Env* helpers all follow the same contract: an unset (or empty) variable
|
||||||
|
// returns def silently; a variable that is set but unparseable — or rejected by
|
||||||
|
// the optional valid predicate — logs once and falls back to def. This keeps the
|
||||||
|
// "parse env, validate, log, default" boilerplate out of every cmd/* main.
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnvString returns the value of key, or def when unset/empty.
|
||||||
|
func EnvString(key, def string) string {
|
||||||
|
if v, ok := os.LookupEnv(key); ok && v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnvInt parses key as an int, validating with valid (nil = accept any).
|
||||||
|
func EnvInt(key string, def int, valid func(int) bool) int {
|
||||||
|
v, ok := os.LookupEnv(key)
|
||||||
|
if !ok || v == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(v)
|
||||||
|
if err != nil || (valid != nil && !valid(n)) {
|
||||||
|
log.Printf("invalid %s %q, using %d", key, v, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnvFloat64 parses key as a float64, validating with valid (nil = accept any).
|
||||||
|
func EnvFloat64(key string, def float64, valid func(float64) bool) float64 {
|
||||||
|
v, ok := os.LookupEnv(key)
|
||||||
|
if !ok || v == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
f, err := strconv.ParseFloat(v, 64)
|
||||||
|
if err != nil || (valid != nil && !valid(f)) {
|
||||||
|
log.Printf("invalid %s %q, using %g", key, v, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnvFloat32 parses key as a float32, validating with valid (nil = accept any).
|
||||||
|
func EnvFloat32(key string, def float32, valid func(float32) bool) float32 {
|
||||||
|
v, ok := os.LookupEnv(key)
|
||||||
|
if !ok || v == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
f, err := strconv.ParseFloat(v, 32)
|
||||||
|
if err != nil || (valid != nil && !valid(float32(f))) {
|
||||||
|
log.Printf("invalid %s %q, using %g", key, v, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return float32(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnvDuration parses key as a time.Duration (e.g. "2m", "30s").
|
||||||
|
func EnvDuration(key string, def time.Duration) time.Duration {
|
||||||
|
v, ok := os.LookupEnv(key)
|
||||||
|
if !ok || v == "" {
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
d, err := time.ParseDuration(v)
|
||||||
|
if err != nil || d <= 0 {
|
||||||
|
log.Printf("invalid %s %q, using %s", key, v, def)
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Package platform is the shared seam library for the e-commerce platform.
|
||||||
|
//
|
||||||
|
// It holds the small, stable interfaces and helpers that every module may
|
||||||
|
// import WITHOUT importing another module's internals: env/config loading,
|
||||||
|
// the AMQP and HTTP client factories, OpenTelemetry setup, graceful shutdown,
|
||||||
|
// and the cross-module event vocabulary.
|
||||||
|
//
|
||||||
|
// Dependency rule: packages under platform/ import only third-party libraries
|
||||||
|
// and other platform/ packages — never an application module. Application
|
||||||
|
// modules depend downward onto platform. This is what keeps it a stable seam.
|
||||||
|
//
|
||||||
|
// See docs/platform-uniforming-plan.md for the layout and the migration order.
|
||||||
|
package platform
|
||||||
Reference in new issue
Block a user