hikan.ru/mvc/models/app.go

44 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package models
import (
"html/template"
"main/mvc/models/models_pages"
"time"
)
type App struct {
Cfg *Config // Сонфиг
Posts models_pages.Posts // Посты
Templates *template.Template // Шаблоны страниц
PagesCache *Cache // Кэш (отрендеренные странички)
LastfmLastTrack string // Последний трек, полученный с ластфм
Version int64 // Время запуска
}
// Инициализирует приложение
func InitApp() (*App, error) {
var err error
app := &App{}
// Версия чтобы статика не кэшировалась
app.Version = time.Now().Unix()
// Загрузка конфига
if app.Cfg, err = loadConfig(ConfigPath); err != nil {
return nil, err
}
// Загрузка постов
if app.Posts, err = models_pages.LoadPosts(app.Cfg.PostsDir); err != nil {
return nil, err
}
// Загрузка шаблонов
if app.Templates, err = loadTemplates(app.Cfg.TemplatesDir, app.Cfg.TemplatesExt); err != nil {
return nil, err
}
// Инициализация кэша
app.PagesCache = initCache()
// Строка по умолчанию для последнего прослушанного трека
app.LastfmLastTrack = "None"
return app, nil
}