implement

This commit is contained in:
2023-10-31 23:26:03 +03:00
parent 1087865b3d
commit 201c6a0425
8 changed files with 735 additions and 1 deletions

37
cmd/simple/config.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"encoding/json"
"os"
)
type config struct {
DSN string `json:"dsn"`
Topic string `json:"topic"`
}
func parseEnvConfig() (cfg config) {
const defaultPath = "./cli.json"
data, err := os.ReadFile(defaultPath)
if err != nil {
if !os.IsNotExist(err) {
panic(err.Error())
}
} else {
err := json.Unmarshal(data, &cfg)
if err != nil {
panic(err.Error())
}
}
if dsn := os.Getenv("SMTH_DSN"); dsn != "" {
cfg.DSN = dsn
}
if topic := os.Getenv("SMTH_TOPIC"); topic != "" {
cfg.Topic = topic
}
return cfg
}