package headscale import ( "bytes" _ "embed" "html/template" "net/http" "github.com/rs/zerolog/log" ) //go:embed gen/openapiv2/headscale/v1/headscale.swagger.json var apiV1JSON []byte func SwaggerUI( w http.ResponseWriter, r *http.Request, ) { swaggerTemplate := template.Must(template.New("swagger").Parse(`
`)) var payload bytes.Buffer if err := swaggerTemplate.Execute(&payload, struct{}{}); err != nil { log.Error(). Caller(). Err(err). Msg("Could not render Swagger") w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("Could not render Swagger")) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) w.Write(payload.Bytes()) } func SwaggerAPIv1( w http.ResponseWriter, r *http.Request, ) { w.Header().Set("Content-Type", "application/json; charset=utf-88") w.WriteHeader(http.StatusOK) w.Write(apiV1JSON) }