diff options
Diffstat (limited to 'api/handlers/html.go')
| -rw-r--r-- | api/handlers/html.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/api/handlers/html.go b/api/handlers/html.go new file mode 100644 index 0000000..dd5d4e8 --- /dev/null +++ b/api/handlers/html.go @@ -0,0 +1,27 @@ +package handlers + +import ( + "net/http" + + "git.leonardobishop.net/history/pkg/entries" + "git.leonardobishop.net/history/pkg/html" +) + +func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + entries, err := entriesService.GetEntries() + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + html, err := htmlService.GenerateHtml(entries) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "text/html;charset=UTF-8") + w.Write([]byte(html)) + } +} |
