50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io"
|
||
|
"os"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
var Cfg *Config
|
||
|
|
||
|
type Config struct {
|
||
|
ServerIP string `json:"SERVER_IP"`
|
||
|
DBPath string `json:"DB_PATH"`
|
||
|
TemplatesPath string `json:"TEMPLATES_PATH"`
|
||
|
GcssPath string `json:"GCSS_PATH"`
|
||
|
TgBotToken string `json:"TG_BOT_TOKEN"`
|
||
|
TgChatID string `json:"TG_CHAT_ID"`
|
||
|
LastfmAPIKey string `json:"LASTFM_API_KEY"`
|
||
|
LastFmUsername string `json:"LASTFM_USERNAME"`
|
||
|
CookieCryptKey string `json:"COOKIE_CRYPT_KEY"`
|
||
|
CookieHMAC string `json:"COOKIE_HMAC"`
|
||
|
SessionKey string `json:"SESSION_KEY"`
|
||
|
SessionTime int `json:"SESSION_TIME_HOURS"`
|
||
|
TgTickerTime time.Duration `json:"TG_TICKER_TIME_HOURS"`
|
||
|
LastFmTickerTime time.Duration `json:"LASTFM_TICKER_TIME_SECONDS"`
|
||
|
MaxPostsOnPage int `json:"MAX_POSTS_ON_PAGE"`
|
||
|
}
|
||
|
|
||
|
func LoadConfig(filename string) error {
|
||
|
file, err := os.Open(filename)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
data, err := io.ReadAll(file)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
var config Config
|
||
|
if err := json.Unmarshal(data, &config); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
Cfg = &config
|
||
|
return nil
|
||
|
}
|