59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
ConfigPath = "config.json"
|
|
)
|
|
|
|
type Config struct {
|
|
pathsConfig
|
|
serverConfig
|
|
lastFMConfig
|
|
cacheConfig
|
|
}
|
|
|
|
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:"max_posts_per_page"`
|
|
}
|
|
|
|
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
|
|
}
|