Config System

This commit is contained in:
2026-06-02 19:21:42 +02:00
parent 6ab31c2c1b
commit 90001720d8
2 changed files with 32 additions and 0 deletions

27
internal/config/config.go Normal file
View File

@@ -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
}

5
settings.json Normal file
View File

@@ -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"
}