package node import ( "net/http" "gitea.difrex.ru/Umbrella/fetcher/i2es" log "github.com/sirupsen/logrus" ) type ssr struct { es ESConf templatesDir string } func newSSR(templatesDir string, es ESConf) *ssr { return &ssr{ es: es, templatesDir: templatesDir, } } type PageData struct { Echoes []echo CurrentPage string Posts []i2es.ESDoc } func (s *ssr) newPageData(page string, posts []i2es.ESDoc) *PageData { return &PageData{ Echoes: s.es.GetEchoesList(), Posts: posts, CurrentPage: page, } } func (s *ssr) ssrRootHandler(w http.ResponseWriter, r *http.Request) { tpl, err := s.getTemplate("root") if err != nil { log.Error(err) return } if err := tpl.Execute(w, s.newPageData("", s.es.GetLatestPosts(50))); err != nil { log.Error(err) } } func (s *ssr) ssrForumHandler(w http.ResponseWriter, r *http.Request) { tpl, err := s.getTemplate("forum") if err != nil { log.Error(err) return } if err := tpl.Execute(w, s.newPageData("", s.es.GetThreads())); err != nil { log.Error(err) } }