github.com/jamiefdhurst/journal@v0.9.2/internal/app/controller/apiv1/single.go (about) 1 package apiv1 2 3 import ( 4 "encoding/json" 5 "net/http" 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 // Single Find and display single blog entry 13 type Single struct { 14 controller.Super 15 } 16 17 // Run Single action 18 func (c *Single) Run(response http.ResponseWriter, request *http.Request) { 19 20 js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))} 21 journal := js.FindBySlug(c.Params[1]) 22 23 response.Header().Add("Content-Type", "application/json") 24 if journal.ID == 0 { 25 response.WriteHeader(http.StatusNotFound) 26 } else { 27 encoder := json.NewEncoder(response) 28 encoder.SetEscapeHTML(false) 29 encoder.Encode(journal) 30 } 31 32 }