| 31 | } |
| 32 | |
| 33 | func handleSwaggerUI(title string) http.HandlerFunc { |
| 34 | return func(w http.ResponseWriter, r *http.Request) { |
| 35 | w.Header().Set("Content-Type", "text/html") |
| 36 | tmpl, err := template.New("swagger-ui").Parse(swaggerUITemplate) |
| 37 | if err != nil { |
| 38 | http.Error(w, "Error rendering UI template", http.StatusInternalServerError) |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | data := struct { |
| 43 | Title string |
| 44 | Path string |
| 45 | }{ |
| 46 | Title: title, |
| 47 | Path: "/api-docs/swagger.json", |
| 48 | } |
| 49 | |
| 50 | err = tmpl.Execute(w, data) |
| 51 | if err != nil { |
| 52 | http.Error(w, "Error rendering UI template", http.StatusInternalServerError) |
| 53 | } |
| 54 | } |
| 55 | } |