From 6d2403d2f57620f132e22143055ff915b68bbb35 Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 8 Jun 2025 15:55:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=20=D1=87?= =?UTF-8?q?=D1=83=D1=82=D1=8C=20=D1=87=D1=83=D1=82=D1=8C,=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=B1=D0=B8=D0=BB=20=D0=BD=D0=B0=20=D0=B2=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC=D1=8B=D0=B5=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/models/config.go | 68 +++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/mvc/models/config.go b/mvc/models/config.go index 0c7b74a..faf36f4 100644 --- a/mvc/models/config.go +++ b/mvc/models/config.go @@ -11,32 +11,48 @@ const ( ) type Config struct { - PostsDir string - PostsMaxCountOnPage int - AssetsDir string - TemplatesDir string - TemplatesExt string - LocalIP string - LocalPort string - ServerIP string - ServerPort string - ServerDomain string - Port string - LastFMUsername string - LastFMToken string - LastFMUpdateInterval time.Duration - CacheLogInterval time.Duration + pathsConfig + serverConfig + lastFMConfig + cacheConfig } -func loadConfig(configPath string) (*Config, error) { - cfg := &Config{} - configFile, err := os.ReadFile(configPath) - if err != nil { - return nil, err - } - err = json.Unmarshal(configFile, cfg) - if err != nil { - return nil, err - } - return cfg, nil +type pathsConfig struct { + PostsDir string `json:"posts_dir"` + AssetsDir string `json:"assets_dir"` + TemplatesDir string `json:"templates_dir"` + TemplatesExt string `json:"templates_ext"` + PostsMaxCountOnPage int `json:"posts_max_count"` +} + +type serverConfig struct { + LocalIP string `json:"local_ip"` + LocalPort string `json:"local_port"` + ServerIP string `json:"server_ip"` + ServerPort string `json:"server_port"` + ServerDomain string `json:"server_domain"` +} + +type lastFMConfig struct { + LastFMUsername string `json:"lastfm_username"` + LastFMToken string `json:"lastfm_token"` + LastFMUpdateInterval time.Duration `json:"lastfm_update_interval"` +} + +type cacheConfig struct { + CacheLogInterval time.Duration `json:"cache_log_interval"` +} + +func loadConfig(path string) (*Config, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + var cfg Config + if err := json.Unmarshal(data, &cfg); err != nil { + return nil, err + } + + return &cfg, nil }