Config System
This commit is contained in:
27
internal/config/config.go
Normal file
27
internal/config/config.go
Normal 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
5
settings.json
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user