From 90001720d82b523c2669c0bac77d398b579aff66 Mon Sep 17 00:00:00 2001 From: KoCoder Date: Tue, 2 Jun 2026 19:21:42 +0200 Subject: [PATCH] Config System --- internal/config/config.go | 27 +++++++++++++++++++++++++++ settings.json | 5 +++++ 2 files changed, 32 insertions(+) create mode 100644 internal/config/config.go create mode 100644 settings.json diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..dde2cbb --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,27 @@ +package config + +import ( + "encoding/json" + "os" +) + +type Config struct { + DB_URL string `json:"db_url"` + TRUSTED_PROXIES []string `json:"trusted_proxies"` + OTLP_ENDPOINT string `json:"otlp_endpoint"` +} + +func Read() *Config { + file, err := os.ReadFile("/home/kocoder/src/go/shortener/settings.json") + if err != nil { + panic(err) + } + + var config Config + err = json.Unmarshal(file, &config) + if err != nil { + panic(err) + } + + return &config +} diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..c954ee5 --- /dev/null +++ b/settings.json @@ -0,0 +1,5 @@ +{ + "db_url": "postgresql://postgres:asdfg12345@127.0.0.1:5432/shortener?sslmode=disable", + "trusted_proxies": ["10.8.0.3"], + "otlp_endpoint": "https://otel.kocoder.xyz" +}