github.com/jamiefdhurst/journal@v0.9.2/internal/app/controller/web/view.go (about) 1 package web 2 3 import ( 4 "net/http" 5 "text/template" 6 7 "github.com/jamiefdhurst/journal/internal/app" 8 "github.com/jamiefdhurst/journal/internal/app/model" 9 "github.com/jamiefdhurst/journal/pkg/controller" 10 ) 11 12 // View Handle displaying individual entry 13 type View struct { 14 controller.Super 15 Journal model.Journal 16 Next model.Journal 17 Prev model.Journal 18 } 19 20 // Run View action 21 func (c *View) Run(response http.ResponseWriter, request *http.Request) { 22 23 js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))} 24 c.Journal = js.FindBySlug(c.Params[1]) 25 26 if c.Journal.ID == 0 { 27 RunBadRequest(response, request, c.Super.Container) 28 } else { 29 c.Next = js.FindNext(c.Journal.ID) 30 c.Prev = js.FindPrev(c.Journal.ID) 31 gs := model.Giphys{} 32 c.Journal.Content = gs.ConvertIDsToIframes(c.Journal.Content) 33 template, _ := template.ParseFiles( 34 "./web/templates/_layout/default.html.tmpl", 35 "./web/templates/view.html.tmpl") 36 template.ExecuteTemplate(response, "layout", c) 37 } 38 }