Files
podinfo/pkg/api/index.go
stefanprodan 2479134e78 Implement swagger support
- add swagger definitions for all API routes
- self-host the swagger UI on `/swagger/`
- serve swagger spec on `/swagger.json`
2019-08-07 14:17:35 +03:00

34 lines
754 B
Go

package api
import (
"html/template"
"net/http"
"path"
)
// Index godoc
// @Summary Index
// @Description renders podinfo UI
// @Tags HTTP API
// @Produce html
// @Router / [get]
// @Success 200 {string} string "OK"
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)
}
}