From aeeb146c2a23128432f1003a32aedbde71c95fa7 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Mon, 20 Aug 2018 11:27:40 +0300 Subject: [PATCH] Add UI handler --- pkg/api/index.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pkg/api/index.go diff --git a/pkg/api/index.go b/pkg/api/index.go new file mode 100644 index 0000000..ebff738 --- /dev/null +++ b/pkg/api/index.go @@ -0,0 +1,26 @@ +package api + +import ( + "html/template" + "net/http" + "path" +) + +func (s *Server) indexHandler(w http.ResponseWriter, r *http.Request) { + tmpl, err := template.New("vue.html").ParseFiles(path.Join(s.config.UIPath, "vue.html")) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(path.Join(s.config.UIPath, "vue.html") + err.Error())) + return + } + + data := struct { + Title string + }{ + Title: s.config.Hostname, + } + + if err := tmpl.Execute(w, data); err != nil { + http.Error(w, path.Join(s.config.UIPath, "vue.html")+err.Error(), http.StatusInternalServerError) + } +}